and we are having a similar problem, but I did not see any resolution in this thread.
We are getting the following error message:
System.InvalidOperationException: Object is currently in use elsewhere. at System.Drawing.Graphics.MeasureString(String text, Font font, PointF origin, StringFormat stringFormat) at ..(String , ) at a..( ) at a..( , ) at a..( , Boolean , Boolean ) at a..( , Boolean ) at a...ctor( ) at ..( , ) at ..( ) at ..( ) at ..(ArrayList , , ) at ..(Document , Stream , DocSaveOptions ).
We are in a multi-threaded environment. Any idea why we are we receiving this? We are using the latest version of Aspose.PDF.
Thanks for your inquiry. I’m afraid its difficult to investigate an issue without reproducing it, and in referenced thread customer identified the issue arises randomly. As you mentioned you are in multi-threaded environment, although Aspose.Pdf for .NET supports multi-threading but one Pdf document should be dealt in one thread. access to a single document from several threads is not supported. Can you please double check whether you are following this? As your error message shows that one document is being access from more than one threads.
Hopefully your issue will be resolved. If issue persist then can you please share some sample application to replicate the issue. So we will investigate it and provide you more information.
We are using only one PDF Document per thread. We are using a combination of Aspose.Word and Aspose.PDF. What we are doing is:
1. A Windows Service creates up to 10 threads. Each thread uses reflection to load an assembly/class and calls a particular method. They all call the same method in the assembly, but load the assembly seperately.
2. The assembly/class/method is responsible for generating a PDF by combining several documents together into one document for one record in our database. We use your components to merge a PDF into a Word Document. The code we use to do the merge is as follows:
using (Aspose.Pdf.Document pdfInsert = new Aspose.Pdf.Document(pdfDocumentToAppendPath)) { using (MemoryStream pdfStream = new MemoryStream()) { Aspose.Pdf.DocSaveOptions saveOptions = new Aspose.Pdf.DocSaveOptions() { Mode = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow, Format = Aspose.Pdf.DocSaveOptions.DocFormat.Doc }; pdfInsert.Save(pdfStream, saveOptions);
using (MemoryStream inputStream = new MemoryStream(pdfStream.ToArray())) { Document insert = new Document(inputStream); doc.AppendDocument(insert, ImportFormatMode.KeepSourceFormatting); } } } }
I cannot create an exact replica of the application because the threading/reflection application piece is a seperate application. We just build the assembly/class that it loads and executes the standard method on.
I have gone through your requirement and the above code snippet and as per my observations, first you are converting the PDF file to DOC format and then trying to merge the PDF files using Aspose.Pdf.Document object. However I have observed that once you have converted the PDF file to DOC format, and after that, if you are trying to merge the DOC files using Aspose.Pdf.Document object, it’s not supported. Furthermore, as per your requirements, I would recommend you to first load all PDF files, merge them using Aspose.Pdf.Document object and once you have the concatenated PDF file, convert it to DOC format.
In above code snippet, I think you are loading individual PDF file, converting it to DOC format and concatenating the DOC files to generate a single large document. We apologize for your inconvenience.
Thank you for the response. We are using both of your products here. Both Aspose.Pdf and Aspose.Words. The Document being passed into the method is Aspose.Words. We are only converting one document from a PDF to Word using Aspose.Pdf. We are then appending the resulting Word document to an existing Word document using Aspose.Words. This all happens in a single thread, however there are multiple threads doing the same thing with different documents etc. The Aspose.Words part seems to work ok; however the Aspose.Pdf we randomly get the error described in my original post.
Thanks for your feedback. Can you please share a sample console application? So we try to replicate it at our end as Its very difficult to investigate an issue without reproducing it and you mentioned issue arises randomly. Moreover, can you please try to download and try latest version of Aspose.Pdf for .NET. Hopefully it resolve the issue as over the time we have made number of enhancements and fixes in API.