Good morning,
we are using Aspose.Words to convert .doc files to .pdf ones (particularly pdf/a) and the code looks like this:
///
/// The (pdf) save options
///
internal static SaveOptions DocumentSaveOptions = new PdfSaveOptions
{
Compliance = PdfCompliance.PdfA1b,
ImageColorSpaceExportMode = PdfImageColorSpaceExportMode.Auto,
FontEmbeddingMode = PdfFontEmbeddingMode.EmbedAll,
EmbedFullFonts = true,
UseHighQualityRendering = true
};
using (var inputFileMemoryStream = new MemoryStream(fileToConvert.Content)) // << fileToConvert.Content is a byte[] containing the .doc
{
// load input document into Aspose lib
var document = new Document(inputFileMemoryStream, new LoadOptions { LoadFormat = LoadFormat.Auto });
cancellationToken.ThrowIfCancellationRequested();
using (var documentToPdfOutputStream = new MemoryStream())
{
// save as pdf
document.Save(documentToPdfOutputStream, DocumentSaveOptions); // **<< THIS is were the exception is happening**
// …
}
}
However, sporadically (this is a multithreaded application and the multiple (different) documents CAN be converted at the same time) we get the following exception:
System.Drawing : System.InvalidOperationException
Object is currently in use elsewhere.
at System.Drawing.Font.ToLogFont(Object logFont, Graphics graphics)
at .(String , Single , FontStyle )
at .(String , Single , FontStyle )
at .(String , Single , FontStyle )
at .(String , Single , FontStyle )
at ? .( , Single )
at ? . ()
at . ()
at . ()
at . ()
at ? .()
at ? .(? , Int32 )
at ? .(? )
at ? .(? )
at ? .(? , Int32 )
at .( , Int32 , Boolean )
at .()
at .( , Int32 , Boolean , Boolean )
at . ()
at .( , Int32 )
at .( )
at .( )
at .( )
at .(Boolean )
at .(Boolean )
at . ()
at .(Document , )
at Aspose.Words.Document.UpdatePageLayout()
at Aspose.Words.Document.(Boolean )
at Aspose.Words.Document. ()
at Aspose.Words.Document.get_PageCount()
at .( , ? )
at .? ( )
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at Backend.Host.AttachmentConverters.AsposeWordsConverter.d__8.MoveNext() in d:\Workspaces\TII\ProductDevelopment\Backend\Backend.Host\AttachmentConverters\AsposeWordsConverter.cs:line 85
---- snip
The version is 14.10.0.0.
What’s going on here? Can I not use Aspose.Words in a multithreaded application?! And/or what can I do to prevent this?
Thanks,
-Jörg B.