Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Oct 19, 2011 4:35 pm

Hi,

I am trying to create a html document to pdf,in my app there isn't a html document to load from file
when specific uri given eg: testreport.aspx

please find the code below


Dim filename As String = test + ".pdf"
Dim path As String = Commons.Files.DownloadPath + filename

Dim doc As New PdfDocument()

Dim url As String = "testreport.aspx"


doc.SaveToFile(path)
doc.Close()
Response.Redirect("/mydownload/" + filename)



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

Please advice me as soon as possible.

Thanks in advanced.

ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Thu Oct 20, 2011 3:04 am

Hello ahamed,

Thank you for your inquiry and sorry for late reply.

Cause the error because of the COM thread model must be single thread. There are two methods to solve it. Firstly, you can use [STAThread] which specified the default Thread apartment is single thread in the application’s entry method. Secondly, you can new a thread.
If you still have any questions, please contact us at any time for any thing.
Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Thu Oct 20, 2011 7:57 am

In relation to my specific issue, could you please give me a sample code in VB.

FYI: I am running this application on 64bit windows 2008 R2 web server.

Thank you.

ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Sat Oct 22, 2011 2:47 am

Hello ahamed,

Sorry for late reply.

I mean that you need specify your main method to be running in single-thread mode. You can consult the following code:
Code: Select all

     <STAThread>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim filename As String = Test + ".pdf"
        Dim path As String = Commons.Files.DownloadPath + filename

        Dim doc As New PdfDocument()

        Dim url As String = "testreport.aspx"


        doc.SaveToFile(path)
        doc.Close()
        Response.Redirect("/mydownload/" + filename)

    End Sub

If you still have any problems, please don't hesitate to contact us.
Have a nice day.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Sat Oct 22, 2011 4:06 am

Hello ahamed,

Sorry for any inconveniences caused by us and thank you for your patience.

I have tried to use <STAThread> before the application entry in different environment but sometimes failed. I attempted to use a new method to solved the problem. I have attached the demo. You can have a try. If you still have any other problems, Please contact us.
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Thu Dec 06, 2012 10:43 pm

I have the same issue and was kind of resolved the active x error but it is throwing another error "A generic error occurred in GDI+."

rbondugula
 
Posts: 1
Joined: Thu Dec 06, 2012 10:33 pm

Fri Dec 07, 2012 2:52 am

Hello rbondugula,

Thanks for your inquiry.
We have done some tests, but we don't reproduce your problem. Could you please tell us the system environment and the version of IE you are using? So that we can reproduce your problem. Thank you!

Best regards,
Amy
E-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF