1

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.

But after a certian time, it bring the new PDF, that means it caching or buffering the byte data somewhere.

Below is my code. every-time I pass a new html file[htmlFullPath] with different images in it.

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;
Derin
  • 1,202
  • 1
  • 15
  • 25
  • findings: If I recycle the Application pool in the local server it come out correctly. But I don't have option in shared hosting server. how can I do it pragmatically? is it safe to do so? – Derin Oct 31 '13 at 03:36

1 Answers1

1

As I mentioned in the question "every-time I pass a new html file[htmlFullPath] with different images in it".

The image for each HTML is different but the Image name was same.

I have renamed the image also with time stamp and all working fine.

That means image with same name making the real problem, it may be a buffering issue of MultiplexingConverter or some settings in the IIS. which I will investigate later.

Derin
  • 1,202
  • 1
  • 15
  • 25