2013-02-06 32 views
0

我使用wkhtmltopdf将一些html转换为pdf。我想我得到一些javascrpot错误,我想从wkhtmltopdf访问一些debug \ logging。有谁知道如何获取日志信息?如何在C#中获取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; 

回答

2

你可以阅读标准错误和标准输出:

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

是你在找什么?

相关问题