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.

HtmlConverter and ASP.NET

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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??

bert

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

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

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


Please try this and let us know if this helps.

Regards,
Pravin Joshua D

Bert Sirkin
Replied On March 11, 2010 08:43 AM

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

Bert Sirkin
Replied On March 11, 2010 10:50 AM

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

Bert Sirkin
Replied On March 11, 2010 01:12 PM

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)
==================================================

bert

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

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.

Regards,
Pravin.






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.

;