H5W3
当前位置:H5W3 > 问答 > 正文

C# web程序关于使用wkhtmltopdf插件无法写入目标文件

try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = exePath;
processStartInfo.WorkingDirectory = Path.GetDirectoryName(exePath);
processStartInfo.UseShellExecute = false;
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.Arguments = GetArguments(htmlPath, savePath);

            Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit();
string fileName = Path.GetFileName(savePath);
///用于查看是否返回错误信息
StreamReader srone = process.StandardError;
StreamReader srtwo = process.StandardOutput;
string ss1 = srone.ReadToEnd();
string ss2 = srtwo.ReadToEnd();
srone.Close();
srone.Dispose();
srtwo.Close();
srtwo.Dispose();
process.Close();
process.Dispose();
flag = true;
}
catch(Exception ex)
{
flag = false;
throw new Exception(ex.ToString());
}

回答

参考使用Spire.PDF for .NET( https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html ) 的转换方法:https://www.e-iceblue.cn/spirepdf/convert-html-into-pdf.html

未经允许不得转载:H5W3 » C# web程序关于使用wkhtmltopdf插件无法写入目标文件

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址