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 Feb 12, 2014 10:41 am

hi.

my application has a timer that once a day will create a pdf using spire.pdf.
when i a trying to do that it gives me an error of current thread is not in a single-threaded apartment.

how can i overcome this problam?

bmilos2727
 
Posts: 7
Joined: Thu Feb 06, 2014 8:04 am

Thu Feb 13, 2014 2:14 am

Hi,

Thanks for your inquiry.
There are some methods only used in the single thread, so you need to achieve it with single thread like the following code.
Sorry for inconvenience caused by us.
Code: Select all
PdfDocument document = new PdfDocument();

Thread thread = new Thread(() =>{

document.LoadFromHTML("test.html", true, true, true);

});

thread.SetApartmentState(ApartmentState.STA);

thread.Start();

thread.Join();

document.SaveToFile("sample.pdf")

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Feb 13, 2014 8:37 am

hi.

i am getting this error:

Error 1 Overload resolution failed because no accessible 'New' is most specific for these arguments: 'Public Sub New(start As System.Threading.ParameterizedThreadStart)'

bmilos2727
 
Posts: 7
Joined: Thu Feb 06, 2014 8:04 am

Thu Feb 13, 2014 9:34 am

Hi,

Thanks for your response.
Sorry that we couldn't locate the reason of the issue based on the information. And we do a demo about the single thread as reference in the attachment, which needs to add the Spire.pdf dlls.
If there are any questions, Please provide us the below information, which may help us to reproduce your issue quickly and offer the solution to you.
1. Dll file list (name + version), for example:
Spire.Doc.dll v4.9.32.3040
Spire.License.dll v4.9.32.3040
Spire.Pdf.dll v2.8.86.3040
2. Operation System, for example:
Windows 7 Enterprise Edition SP1 x64
Regional and Language Options
3. Project can reproduce the issue
All code about this problem, a simple project which can reproduce this problem will be better.
4. Test Document or Test data
Please provide your test document to us if convenient, it may help us reproduce your issue quickly. We promise to keep your document confidential and we will not use it for any other purpose. Besides, you could also remove the security data of your document and then send it to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Feb 13, 2014 10:45 am

hi.

thanks it works perfect but the downside is that i cant send parameters to the CreatePdfMethod.

bmilos2727
 
Posts: 7
Joined: Thu Feb 06, 2014 8:04 am

Fri Feb 14, 2014 2:26 am

Hi,

Thanks for your response.
Please refer the demo in the attchment.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Feb 18, 2014 8:53 am

Hello,

Has the issue been resolved? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Feb 26, 2014 7:20 am

hi gary.

yes it works very good right now.

i made an object of all my data that i need and send it to the new thread.

thanks.

bmilos2727
 
Posts: 7
Joined: Thu Feb 06, 2014 8:04 am

Wed Feb 26, 2014 8:39 am

Thanks.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Feb 28, 2014 2:00 pm

Unfortunately I'm getting exactly this error also:-

Code: Select all
"Message":"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.","Error":{"ClassName":"System.Threading.ThreadStateException","Message":"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)\r\n   
at System.Windows.Forms.WebBrowser..ctor()\r\n   
at Spire.Pdf.HtmlConverter.HtmlConverter.ᜀ()\r\n   
at Spire.Pdf.HtmlConverter.HtmlConverter..ctor()\r\n   
at Spire.Pdf.PdfSection.LoadFromHTML(String url, Boolean enableJavaScript, Boolean enableHyperlinks, PdfHtmlLayoutFormat layoutFormat)\r\n   
at Spire.Pdf.PdfDocument.LoadFromHTML(String Url, Boolean enableJavaScript, Boolean enableHyperlinks, Boolean autoDetectPageBreak)\r\n


From the following threaded code:-
Code: Select all
public static void Create(string urltoconvert, string savepath)
        {
            var doc = new PdfDocument();
            var thread = new Thread(() => doc.LoadFromHTML(urltoconvert, false, true, true));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            doc.SaveToFile(savepath);
            doc.Close();
            System.Diagnostics.Process.Start(savepath);
        }


I have this in a seperate class library (dll) from my application. I did wonder if I have to thread the call to the dll from my main application?

Code: Select all
Pdf.Generate.Create(url, filepath);


Any help would be appreciated.

drubert
 
Posts: 2
Joined: Fri Feb 28, 2014 1:55 pm

Fri Feb 28, 2014 6:48 pm

Ok, so I managed to get a little further and get round the previous problem. Now, I finally have created some PDFs using LoadHTML and the quality is really poor. The text rendering is an image of the content and not PDF Text. So, I thought I'd try your new HTMLConverter

I have set VS up so that on build it copies all the files to bin/plugins as instructed and I have a setup like this post build:-

/bin
|- /plugins
|--- /bearer
|--- /imageformats
|--- /platforms
|--- HTMLConverter.cs
|--- ...numerous other .dlls (Qt, ssleay32 etc.)
|- Spire.Pdf.dll
|- Spire.License.dll
|- ...other dlls for project...

But on runtime get an error:-

"The conversion provider cann't be found.\r\nPlease make sure:\r\n1. the folder \"plugins\" under the same folder of Spire.Pdf.dll\r\n2. exists \"plugins\\HTMLConverter.dll\" and other \"plugins\\*.dll\""

I'm unsure what to do now. I've spent most of the day trying to get this to work and I'm close to giving up and trying something else. :(

drubert
 
Posts: 2
Joined: Fri Feb 28, 2014 1:55 pm

Mon Mar 03, 2014 3:25 am

Sorry for late reply as weekend.
What's your system? We could provide you the relevant demo.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Mar 04, 2014 6:55 am

Hello,

There is a full demo for X32 system(http://www.e-iceblue.com/downloads/temp/HtmlToPdf.zip), you could download and try it.
If your system is X64, you only replace the plugin folder under the debug folder.

you could get the new plugin from the download file directly:
For X32: http://www.e-iceblue.com/downloads/HTML ... .2.3.3.zip
For X64: http://www.e-iceblue.com/downloads/HTML ... .3-x64.zip

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Mar 07, 2014 9:21 am

Hello,

Have you tested the demo? Does the code meet your need? Could you please give us some feedback if convenience.
If there are any questions, welcome to get it back to us.

Regards,
Benjamin
E-iceblue support team
User avatar

Benjamin Du
 
Posts: 82
Joined: Thu Jul 25, 2013 2:38 am

Fri Dec 05, 2014 8:47 am

Hi.

I'm working on a .NET web application and I'm experiencing the same problem that drubert had.

Under my application Bin folder, I've copied all the dlls and plugins as instructed.

/bin
|- /plugins
|--- /bearer
|--- /imageformats
|--- /platforms
|--- HTMLConverter.cs
|--- ...numerous other .dlls (Qt, ssleay32 etc.)
|- Spire.Pdf.dll
|- Spire.License.dll
|- ...other dlls for project...

And my application's exhibiting the following error message.

"The conversion provider cann't be found.\r\nPlease make sure:\r\n1. the folder \"plugins\" under the same folder of Spire.Pdf.dll\r\n2. exists \"plugins\\HTMLConverter.dll\" and other \"plugins\\*.dll\""

I've looked through the demo you uploaded on March 4th, and I don't find it any help to finding my way out of this.
I'm willing to purchase your product as soon as I get this demo working, so please get to me ASAP.

DONUS
 
Posts: 1
Joined: Fri Dec 05, 2014 2:33 am

Return to Spire.PDF