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.
Unfortunately, activation email could not send to your email. Please try again.

HTML string to PDF conversion = COM exception

Thread ID:

Created:

Updated:

Platform:

Replies:

79269 Jan 27,2009 10:18 AM Oct 13,2009 08:35 AM ASP.NET Web Forms (Classic) 3
loading
Tags: PDF
Sean
Asked On January 27, 2009 10:18 AM

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 08:25 AM

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



Balasubramanian
Replied On October 8, 2009 10:28 AM

Hi Bhuvana,

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



Error_4a5f75e0.rar

Thiruvenkadam E [Syncfusion]
Replied On October 13, 2009 08:35 AM

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

CONFIRMATION

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.

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.

;