We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

General GDI+ Exception by Html to Pdf conversion

Hello,
I am trying to convert a HTML page to a pdf with your product. I use the IE HtmlRenderingEngine and I was able to run a successful conversion with a trivial page on the internet. But now that I tried to convert the page I actually want to I get a Error.

The url to the page I want to convert: https://oms.prolitteris.ch/v2/

Error Stack trace:
2017-04-11 12:24:32.6869 Fatal ProLitteris.PLVS.Services.MFPdfCreator.Logic - Unhandeled Exception in "MFPdfCreator_Test": System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occured in GDI+.
   at System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type, String description)
   at System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type)
   at Syncfusion.HtmlConverter.HtmlConverter.ToImage(Size size)
   at Syncfusion.HtmlConverter.HtmlConverter.GetImagesFromUrl(String url, ImageType type)
   at Syncfusion.HtmlConverter.HtmlConverter.Convert(String url, ImageType type, Int32 width, Int32 height, AspectRatio aspectRatio)
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.ConvertHTMLtoPDF(HtmlConverter html, PdfDocument document, PdfPage page, String url, Single width, Single height, IHtmlConverterSettings ConverterSettings, PdfMetafileLayoutFormat metafileFormat)
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.<>c__DisplayClass2.<Convert>b__0()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The method call looks like this:
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
PdfDocument document = htmlConverter.Convert(url);

Could you please look this up?
I've spent now couple of hours searching for a solution but found nothing.

Thank you

3 Replies

PV Prakash Viswanathan Syncfusion Team April 12, 2017 10:46 AM UTC

Hi Severin, 
 
Thanks for contacting Syncfusion support. 
 
We are not able to reproduce the General GDI+ exception in IE rendering engine. While converting the provided webpage (https://oms.prolitteris.ch/v2/) to PDF, the conversion hangs on our end. We have converted the same webpage to PDF using our new WebKit HTML converter, it converts fine. So, we suggest you to try our new WebKit HTML converter, it has more features and enhancement than IE based HTML converter.  
 
Refer below link for more information about WebKit HTML converter.  
 
 
We have attached the output document for your reference, which is converted using WebKit HTML converter.  
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Prakash V 



SA Severin Amacher April 12, 2017 11:57 AM UTC

Thank you for your reply I have a slight idea of why the Error occured.
It had something to do with the document ready javascript that should have been executed.
The IE based Converter seems to not wait for the document ready js code to finish. Anyway I know use the WebKit with EnableJavaScript = true and it works flawless.

Thank you for your fast response.


PV Prakash Viswanathan Syncfusion Team April 13, 2017 11:18 AM UTC

Hi Severin, 
 
We try to reproduce the GDI+ exception with IE HTML converter, but the conversion still hangs on our end. IE based HTML to PDF converter will wait for document load complete event, but we should set EnableJavaScript to true and use AdditionalDelay in IEConverterSettings to load the external CSS and JS. Please make use of additional delay to overcome this behavior.  
 
Please refer below code snippet to set additional delay. 
//Set AdditionalDelay 
IEsetting.AdditionalDelay = 5000; 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Prakash V 


Loader.
Up arrow icon