pruiz / WkHtmlToXSharp

C# wrapper wrapper (using P/Invoke) for the excelent Html to PDF conversion library wkhtmltopdf library.
239 stars 84 forks source link

HTML to PDF conversion using WkHtmlToXSharp Caching Issue #20

Closed derinpdavis closed 10 years ago

derinpdavis commented 10 years ago

I want to convert an HTML file to PDF file, and I was using "wkhtmltopdf.exe". Then we moved this application to a shared hosting server. This server, wouldn't allow to run .exe files, so that I have to use the WkHtmlToXSharp.dll [wrapper for the above exe].

Its working fine but the problem is this it caching the output somewhere, so that every-time I create a new PDF, it always giving the first one.

I have called .Dispose() and setting the converter to null but no use.

Below is my code. every-time I pass a new html file[htmlFullPath] with different images in it. Also I am setting the margins 0cm for all sides, but not working.

IHtmlToPdfConverter converter = new MultiplexingConverter();

converter.ObjectSettings.Page = htmlFullPath;

converter.ObjectSettings.Web.EnablePlugins = true;
converter.ObjectSettings.Web.EnableJavascript = true;
converter.ObjectSettings.Web.Background = true;
converter.ObjectSettings.Web.LoadImages = true;
converter.ObjectSettings.Load.LoadErrorHandling = LoadErrorHandlingType.ignore;

converter.GlobalSettings.Orientation = (PdfOrientation)Enum.Parse(typeof(PdfOrientation), orientation);
if (!string.IsNullOrEmpty(pageSize))
    converter.GlobalSettings.Size.PageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pageSize);

converter.GlobalSettings.Margin.Top = "0cm";
converter.GlobalSettings.Margin.Bottom = "0cm";
converter.GlobalSettings.Margin.Left = "0cm";
converter.GlobalSettings.Margin.Right = "0cm";

Byte[] bufferPDF = converter.Convert();

System.IO.File.WriteAllBytes(pdfUrl, bufferPDF);

converter.Dispose();
converter = null;