In my VB.NET project for the web service, I added references to the AxInterop.PDFXCviewAxLib.dll and Interop.PDFXCviewAxLib.dll. I then created a new instance of the control like this:
Code: Select all
'Create an instance of the control
Dim AxCoPDFXCview1 As New AxPDFXCviewAxLib.AxCoPDFXCview()
ActiveX control cannot be instantiated because the current thread is not in a single-threaded apartment.
Because of this, I modified my code to try to handle the threading issue like this:
Code: Select all
Dim t As New Thread(New ParameterizedThreadStart(AddressOf RunThis))
t.SetApartmentState(ApartmentState.STA)
t.IsBackground = True
t.Start()
t.Join()
Code: Select all
AxCoPDFXCview1.OpenDocument("C:\Temp\Examples\EBYD.pdf", "", iActiveDocID, 0)
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.
I am starting to think that this is not the best way to handle this situation. Surely someone else has developed a web service that works with PDF-XChange Viewer. I have experimented with opening the file from a file stream with similar results. What would be an alternate way to do this? Is there a preferred way to load & print files that doesn't require rendering the document on a GUI? I thought I shouldn't be using the ActiveX control, but I wasn't sure what the alternative would be.
I would greatly appreciate any suggestions.
Thank you,
Karl