C# 为什么从CMD运行时得到的结果与从web服务运行时不同?(PDF格式)
我正在使用以下代码生成pdf文件:C# 为什么从CMD运行时得到的结果与从web服务运行时不同?(PDF格式),c#,asp.net,asp.net-core-3.1,wkhtmltopdf,C#,Asp.net,Asp.net Core 3.1,Wkhtmltopdf,我正在使用以下代码生成pdf文件: private async Task<byte[]> GerarPDF(string html, string chaveArquivo, string caminhoSalvar, string urlHeader, string urlFooter) { var caminhoPdf = $@"{caminhoSalvar}\{chaveArquivo}.pdf"; string h
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;
}
}
当我在CMD中执行该命令行时,pdf完全是用一个页面创建的,但是当我从API执行时,pdf是用正确的页面和另外两个只有页眉的白色页面生成的
为什么要用这两个额外的页面生成pdf
编辑1:
参数的精确值:
$@“-q-s A4--加载错误处理忽略--头htmlhttps://SomeSite.com.br C:\WINDOWS\TEMP\615f7abf-dd64-4b6f-b76c-7a58d9f0793e.html C:\Contratos\declaraceos\D38D200D.pdf&&C:\Fiap\Updown\Contratos\declaraceos\D38D200D.pdf“
删除&
及其后的路径并使其生效,谢谢parametros的确切值是多少?parametros的确切值:$@“-q-s A4--加载错误处理忽略--标题htmlhttps://SomeSite.com.br C:\WINDOWS\TEMP\615f7abf-dd64-4b6f-b76c-7a58d9f0793e.html C:\Contratos\declaraceos\D38D200D.pdf和&C:\Contratos\declaraceos\D38D200D.pdf”
这个和&
是什么意思?我想你是在用它来发布PDF?如果删除它,然后在调用WaitForExit
后启动PDF,会发生什么?@mjwills我删除了&&和它之后的路径,它成功了,谢谢
wkhtmltopdf.exe -q -s A4 --load-error-handling ignore --header-html https://SomeSite.com.br C:\WINDOWS\TEMP\615f7abf-dd64-4b6f-b76c-7a58d9f0793e.html C:\Contratos\Declaracoes\D38D200D.pdf && C:\Fiap\Updown\Contratos\Declaracoes\D38D200D.pdf