1

我正在使用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;
4

1 回答 1

2

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

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

那是你要找的吗?

于 2013-02-06T23:03:26.343 回答