【问题标题】:How to get wkhtmltopdf logging info in C#?如何在 C# 中获取 wkhtmltopdf 日志信息?
【发布时间】:2013-01-21 22:35:16
【问题描述】:

我正在使用wkhtmltopdf 将一些 html 转换为 pdf。我想我遇到了一些 javascrpot 错误,我想从 wkhtmltopdf 访问一些调试\日志记录。有谁知道如何获取日志信息?

        var wkhtmlDir = Settings.HtmlToPdfFolderPath;
        var wkhtml = Settings.HtmlToPdfExePath;
        var p = new Process();

        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.FileName = wkhtml;
        p.StartInfo.WorkingDirectory = wkhtmlDir;

        string switches = "";
        switches += "--print-media-type --redirect-delay 800 ";
        //switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm ";
        switches += "--page-size Letter ";
        p.StartInfo.Arguments = switches + " " + url 
        p.Start();

        //read output
        byte[] buffer = new byte[32768];
        byte[] file;
        using (var ms = new MemoryStream())
        {
            while (true)
            {
                int read = p.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length);

                if (read <= 0)
                {
                    break;
                }
                ms.Write(buffer, 0, read);
            }
            file = ms.ToArray();
        }

        // wait or exit
        p.WaitForExit(60000);

        // read the exit code, close process
        int returnCode = p.ExitCode;
        p.Close();

        //return returnCode == 0 ? file : null;

        return file;

【问题讨论】:

    标签: c# pdf-generation wkhtmltopdf


    【解决方案1】:

    可以读取标准错误和标准输出:

    String output =string.Format("STD: {0}\nErr: {1}", p.StandardOutput.ReadToEnd(), p.StandardError.ReadToEnd());

    这就是你要找的吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2016-03-19
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 2018-12-15
      相关资源
      最近更新 更多