Reputation: 2192
I am using wkhtmltopdf to create PDF from given HTML. Basically we have some graphs/chart based reports, so we create HTML using our C# code and then use WKHTMLTOPDF to create PDF. It was working fine, but yesterday it stop to creating PDF. I try to debug and process works without any error or message. Just we didn't get PDF as output. I try to run and use Wkhtmltopdf.exe from command line and it does create PDF with all verbose as expected.
my Code is
public static bool HTMLtoPDF(string HTMLPath, string PDFPath, PageOrientation orientation)
{
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
{
string dir = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Vikasumit.VSCommon)).Location) + "\\wkhtmltopdf\\";
proc.StartInfo.WorkingDirectory = dir;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = dir + "wkhtmltopdf.exe";
if (orientation == PageOrientation.Landscape)
{
proc.StartInfo.Arguments = " --page-width 11in --page-height 8.5in --margin-left 0.5cm --margin-right 0 --margin-top 1.25cm --margin-bottom 0 " + HTMLPath + " " + PDFPath;
}
else
{
proc.StartInfo.Arguments = " --page-width 8.5in --page-height 11in --margin-left 0.5cm --margin-right 0 --margin-top 1.25cm --margin-bottom 0 " + HTMLPath + " " + PDFPath;
}
proc.Start();
proc.WaitForExit();
string result = proc.StandardOutput.ReadToEnd();
proc.Close();
proc.Dispose();
}
return false;
}
Indeed this works fine, This code works fine for PDF with one or 2 pages, but this report has 800 page [about 1.2MB HTML file and output file from cmmand line goes around 2.3MB.]
Any idea what might be going wrong in here? It is memory assign to task is limited or what? Thanks.
Upvotes: 2
Views: 1615
Reputation: 181
I use the Rotativa nuget component to wrap the wkhtmltopdf executable in my web app. I do not save to file, but rather use it to download pdf for client...
1) They do suggest to add the ignore load error switch (not sure what it covers) --load-error-handling ignore
2) Since your writing to disk, and it only happens on large files, is there a disk space issue?
Upvotes: 1