- Home
- Forum
- ASP.NET Web Forms (Classic)
- HTML string to PDF conversion = COM exception
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.
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.
SIGN IN To post a reply.
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
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
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
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
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
SE Sean
- Jan 27, 2009 03:18 PM UTC
- Oct 13, 2009 12:35 PM UTC