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

HtmlConverter and ASP.NET

Thread ID:





93354 Mar 10,2010 09:00 PM UTC Mar 18,2010 06:40 AM UTC ASP.NET Web Forms (Classic) 5
Tags: PDF
Bert Sirkin
Asked On March 10, 2010 09:00 PM UTC

I'm trying to create a "hello world" ASP.NET program to convert an existing html page to a pdf. Based on the sample code I've been able to find, I have this so far:

Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim html As New HtmlConverter
Dim img As System.Drawing.Image = html.ConvertToImage("http://www.mysite.com", ImageType.Bitmap)
Dim Image As PdfImage = New PdfBitmap(img)
Dim fmt As New PdfLayoutFormat
fmt.Break = PdfLayoutBreakType.FitPage
fmt.Layout = PdfLayoutType.Paginate
Image.Draw(page, New RectangleF(0, 0, 700, 1000), fmt)

But, the HtmlConverter class seems to require a reference to Windows.Forms and I get the error:

"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."

Can the HtmlConverter class be used with ASP.NET??


Pravin Joshua D [Syncfusion]
Replied On March 11, 2010 05:55 AM UTC

Hi Bert,

Thank you for using Essential PDF.

Yes. The HTMLConverter class can be used with Asp.net.Please make the following change in your web project.

Required Modification:

Include the attribute AspCompat="true" in the @Page directive.

Here is the code snippet

<%@ Page Language="C#" AutoEventWireup="true" AspCompat="true" %>

Please try this and let us know if this helps.

Pravin Joshua D

Bert Sirkin
Replied On March 11, 2010 01:43 PM UTC

Thanks - that worked.

Although I can get a public static website to convert, I can't get one of our secured web sites to convert. I'm getting the following error:

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

Our code requires a valid server session - does the conversion process take place in the same server session?


Bert Sirkin
Replied On March 11, 2010 03:50 PM UTC

It appears that the error:

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

occurs when I try to pass the CONVERT method of the HtmlConverter class HTML instead of a URL. Once the error occurs, I have to shut down Visual Studio, otherwise the CONVERT method won't ever work again, even when passing a URL.

Is there anything special I need to do when I pass a pages HTML to the method? For what it's worth, I picked a simple static public webpage: http://www.w3schools.com/ for testing.


Bert Sirkin
Replied On March 11, 2010 06:12 PM UTC

One last thing - I've tried rendering the HTML two different ways - both with the same error:

Dim imgHTML As System.Drawing.Image = Nothing
imgHTML = html.FromString(sHTML, "http://mysite.com", ImageType.Metafile, 1000, -1, AspectRatio.KeepWidth)
Dim result As HtmlToPdfResult = Nothing
result = html.Convert(sSource, "http://mysite.com", ImageType.Metafile, 1000, -1, AspectRatio.KeepWidth)


Pravin Joshua D [Syncfusion]
Replied On March 18, 2010 06:40 AM UTC

Hi Bert,

We are unable to reproduce the issue.Could you please report these issue with your sample through Direct Trac Developer Support Systemhttps://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents because you can take the advantage of the expertise of a dedicated support engineer and a guaranteed response time and we hope you will take advantage of this system as well. If you have already reported, please ignore this.

Please let us know if you have any other questions.



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

or the page will be automatically redirected to 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