为什么从CMD运行时得到的结果与从web服务运行时不同?(wkhtmltopdf)



我正在使用此代码生成pdf文件:

private async Task<byte[]> GerarPDF(string html, string chaveArquivo, string caminhoSalvar, string urlHeader, string urlFooter)
{
var caminhoPdf = $@"{caminhoSalvar}{chaveArquivo}.pdf";
string htmlTemporario = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".html");
File.WriteAllText(htmlTemporario, html);
var parametros = " -q -s A4 --load-error-handling ignore ";
if (!string.IsNullOrEmpty(urlHeader))
parametros += $@" --header-html {urlHeader} ";
if (!string.IsNullOrEmpty(urlFooter))
parametros += $@" --footer-html {urlFooter} ";

parametros += $@" {htmlTemporario} {caminhoPdf} && {caminhoPdf} ";
var processo = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Path.Combine(DiretorioWK, WK),
Arguments = parametros,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = DiretorioWK,
CreateNoWindow = true
}
};
processo.Start();
string error = processo.StandardError.ReadToEnd();
processo.WaitForExit();
if (!string.IsNullOrEmpty(error))
{
throw new Exception(error);
}

var byteArray = File.ReadAllBytes(caminhoPdf);
File.Delete(htmlTemporario);
return byteArray;
}
}

此代码产生一个执行以下命令行的过程:

wkhtmltopdf.exe  -q -s A4 --load-error-handling ignore  --header-html https://SomeSite.com.br C:WINDOWSTEMP615f7abf-dd64-4b6f-b76c-7a58d9f0793e.html C:ContratosDeclaracoesD38D200D.pdf && C:FiapUpdownContratosDeclaracoesD38D200D.pdf 

当我在CMD中执行命令行时,pdf是用一个页面完美创建的,但当我从API执行时,pdf会用正确的页面和另外两个只有标题的白色页面生成。

为什么用这两个额外的页面生成pdf?

编辑1:

参数的精确值:$@" -q -s A4 --load-error-handling ignore --header-html https://SomeSite.com.br C:WINDOWSTEMP615f7abf-dd64-4b6f-b76c-7a58d9f0793e.html C:ContratosDeclaracoesD38D200D.pdf && C:FiapUpdownContratosDeclaracoesD38D200D.pdf "

删除&&及其后的路径,它就工作了,感谢

最新更新