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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

HTML string to PDF conversion = COM exception

Thread ID:





79269 Jan 27,2009 03:18 PM UTC Oct 13,2009 12:35 PM UTC ASP.NET Web Forms (Classic) 3
Tags: PDF
Asked On January 27, 2009 03:18 PM UTC

I'm trying to convert an html string to a pdf using the example code given online and in the samples. Regular conversion from a url works perfectly fine. But converting a string of html is giving me problems. Here's my code:

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);

HtmlConverter html = new HtmlConverter();
html.AutoDetectPageBreak = true;
System.Drawing.Image img = html.FromString(File.ReadAllText("test.html"), ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth);
PdfMetafile metafile = (PdfMetafile)PdfImage.FromImage(img);
metafile.Draw(page, new RectangleF(0, 0, img.Width, img.Height));//, format);

doc.Save("test.pdf", Response, HttpReadType.Save);

COM Error
Error HRESULT E_FAIL has been returned from a call to a COM component.

Happens at the call to HtmlConverter.FromString.

Bhuvaneswari P [Syncfusion]
Replied On January 28, 2009 01:25 PM UTC


I am afraid that I am unable to reproduce the issue. Its working fine in our end without any COM exception.

Please have a look into the below article regarding HTML to PDF conversion:

If you still able to reproduce the COM exception, could please send us your sample with the below details.

1. OS details
2. Browser version details.
3. Essential Studio version

This would be very helpful for us to reproduce the issue and find out the cause of the issue.

Best Regards,

Replied On October 8, 2009 02:28 PM UTC

Hi Bhuvana,

I am getting this same issue. XP, .Net2008.


Thiruvenkadam E [Syncfusion]
Replied On October 13, 2009 12:35 PM UTC

Hi Socone,

I regret for the long delay in getting back to you on this.


I am fear that still i couldn't able to reproduce the reported issue in our side.

The conversion from HTML to PDF is achieved as follows :

1) HTML Pages specified in the URL is first imported to PDF with the help of "HtmlConverter.Base.dll".
2) The HtmlConverter uses the MSHTML (Is a engine used to drive the browser) library which renders the HTML page.
3) HTMLConverter converts the HTML page to bitmap image or as a metafile image.
4) The Image is then rendered into the PDF document.

Please do find the sample from the below specified location which demonstrates the Html To PDF feature.


Can you check whether you have the Microsoft.MsHTML.dll present in the webserver GAC. If you could not find there, Please drag and drop this assembly from the below location on
to GAC.

[Default Drive] or C:\Program Files\Microsoft.NET\Primary Interop Assemblies

Basically, the Microsoft.MSHTML.dll should be present in the GAC.

Also can you add add the AspCompact="true" attribute to the page directive in Default.aspx file.

Could you please look at the below location if you need more information about HtmltoPDF conversion.


Please have a look at the above sample and if still the issue exists,

Could you please try to reproducing it in the above sample or send us html files so that we could sort out the cause of the issue and provide you a solution?

Please let us know if you need any further information.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon