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
close icon

HTML string to PDF conversion = COM exception

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.


3 Replies

BP Bhuvaneswari P Syncfusion Team January 28, 2009 01:25 PM UTC

Hi,

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:
http://www.syncfusion.com/products/PDF/Backoffice/Articles/html_to_pdf.aspx

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,
Bhuvana




BA Balasubramanian October 8, 2009 02:28 PM UTC

Hi Bhuvana,

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



Error_4a5f75e0.rar


TE Thiruvenkadam E Syncfusion Team October 13, 2009 12:35 PM UTC

Hi Socone,

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

HRESULT E_FAIL error

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.

http://files.syncfusion.com/support/pdf.Windows/I58121/HtmlToPdf.zip

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.

http://help.syncfusion.com/ug_73/pdf/HTMLToPDF.html

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.

Regards,
Thiru

Loader.
Live Chat Icon For mobile
Up arrow icon