pruiz / WkHtmlToXSharp

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

Only works first time #7

Closed datimson closed 12 years ago

datimson commented 12 years ago

Hi,

I'm trying to generate a PDF from a html string using the following code in an asp.net web application:

    public static MemoryStream WkHtmlToXSharp_ConvertToPDF(string wHTML)
        {
            MemoryStream msOutput = new MemoryStream();
            WkHtmlToXSharp.MultiplexingConverter htmlToPdfConverter = new MultiplexingConverter();
            htmlToPdfConverter.ObjectSettings.Load.LoadErrorHandling = LoadErrorHandlingType.ignore;
            byte[] pBytes = htmlToPdfConverter.Convert(wHTML);
            htmlToPdfConverter.Dispose();
            msOutput.Write(pBytes, 0, pBytes.Length);
            return msOutput;
        }

I then return the stream to the browser to download. Anyway, it works great the first time, but the second time I run this the generated PDF is plain text (all images, styles and layout such as tables ect are missing).

Can you please help me?

Regards Dean

datimson commented 12 years ago

It seems my problem was I forgot to set the project platform target setting to x86 instead of any cpu. It also caused the IIS worker process (w3wp.exe) to run at 100% cpu usage until I did a recycle on the application pool.

datimson commented 12 years ago

Also, for the sake of helping anyone else who might have this problem, when debugging with WkHtmlToXSharp in ASP.NET you need to stop the ASP Development server before restarting or rebuilding the application - this is what was causing my text only PDF outputs.

abedijoo commented 12 years ago

I don not understand exactly how this problem could resolve? Please explain more... (I published the related project that used WkHtmlToXSharp.dll in IIS7.5, and this problem occur again.)

datimson commented 12 years ago

What problem are you having, text only output OR the IIS worker process (w3wp.exe) is running at 100% cpu usage?

abedijoo commented 12 years ago

Both of them.... PDF generated in plan text(all images, styles and layout such as tables ect are missing). IIS worker process (w3wp.exe) is running at 100% cpu usage

what are the solutions?

datimson commented 12 years ago

OK, well I'll try to be as clear as I can:

To fix "IIS worker process (w3wp.exe) is running at 100% cpu usage": WkHtmlToXSharp is not 64bit compatible so you need to make sure your visual studio project 's settings have platform target set to x86 OR when you deploy it to IIS you can run it in a 32bit only application pool.

To fix "IIS worker process (w3wp.exe) is running at 100% cpu usage": I only had this problem on my development machine when running my application from visual studio, not in IIS. However, what I needed to do was close the ASP Development server before restarting the application each time.

I hope this helps.