Word to PDF produces a random GDI+ exception

Hi,

We’re getting a random, difficult to reproduce GDI+ exception using Aspose.Words 11.1.0.0 to convert Word documents with included bitmaps to PDF. Once an error occurs, any Word document with bitmap images causes this issue. We have to kill the w3 worker process every time to remove it or recycle the IIS application pool. The code snippet is as below:

var documentBytes = GetWordDocumentByteArray();
using (var outStream = new MemoryStream())
{
    using (var ms = new MemoryStream(documentBytes))
    {
        var doc = new Aspose.Words.Document(ms);
        doc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
        return outStream.ToArray();
    }
}

Below’s the exception stack trace. Please advise kindly.

Message: A generic error occurred in GDI+.
Stack Trace: at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at xf9a9481c3f63a419.x3cd5d648729cd9b6.xb9b8a93cc6513f40(Image xe058541ca798c059, Stream xcf18e5243f8d5fd3)
at xf9a9481c3f63a419.x3cd5d648729cd9b6.x76d9d85825f57cda(Stream xcf18e5243f8d5fd3)
at xf9a9481c3f63a419.x3cd5d648729cd9b6.x0acd3c2012ea2ee8(Stream xcf18e5243f8d5fd3, xea9682d94fc23852 x0182a6dae298f8a4)
at x4f4df92b75ba3b67.x20a936294adb09c3..ctor(x4882ae789be6e2ef context, x5e9754e56a4f759f brush)
at x4f4df92b75ba3b67.x02cd5c9c8d54330e.xa934c26af07952ed(x845d6a068e0b03c5 xd8f1949f8950238a, x4882ae789be6e2ef x0f7b23d1c393aed9)
at x4f4df92b75ba3b67.xe21bbe9dfab6c4dd.x8b5c019bff4c2d02(x845d6a068e0b03c5 xd8f1949f8950238a)
at x4f4df92b75ba3b67.xa3d3e9bf30ebb072.x3a53bab86bc1dfad(x845d6a068e0b03c5 xd8f1949f8950238a, Boolean x577adbf0cae935c5)
at x4f4df92b75ba3b67.xd6b2a42851fedfba.x4f6d0716f281880f(xab391c46ff9a0a38 xe125219852864557)
at x4f4df92b75ba3b67.x92faf2a956f0f5a7.VisitPathStart(xab391c46ff9a0a38 path)
at x1c8faa688b1f0b0c.xab391c46ff9a0a38.Accept(xf51865b83a7a0b3b visitor)
at x1c8faa688b1f0b0c.xbaec545ec01f92ca.Accept(xf51865b83a7a0b3b visitor)
at x1c8faa688b1f0b0c.xb8e7e788f6d59708.Accept(xf51865b83a7a0b3b visitor)
at x1c8faa688b1f0b0c.xbaec545ec01f92ca.Accept(xf51865b83a7a0b3b visitor)
at x1c8faa688b1f0b0c.xc67adcdbca121a26.Accept(xf51865b83a7a0b3b visitor)
at x6a671772ec29137f.xcd769e39c0788209.DoRenderPage(xc67adcdbca121a26 page)
at xf989f31a236ff98c.x6c74398bceb133f8.xa2e0b7f7da663553(x8556eed81191af11 x5ac1382edb7bf2c2)
at Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c)
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat)

Hi Vadym,

Thanks for your inquiry. I would suggest you please upgrade to the latest version (v14.10.0) from here and let us know how it goes on your side. If the problem still remains, please attach your input Word document here for testing. I will investigate the issue on my side and provide you more information.

Thanks for your response, Tahir!
We’re using Aspose.Words for .NET. Are you suggesting that we upgrade to the latest trial version of Aspose in the mean time?

Hi Vadym,

Please accept my apologies for your inconvenience. Yes, please use the latest version of Aspose.Words for .NET 14.10.0. Hope this helps you.

If you still face problem, please share your input document here for testing purpose. I will
investigate the issue on my side and provide you more information.

Hi,

We’re in the process of evaluating Aspose.Words 15.12 for .Net and are getting the same intermittent GDI+ exception as before. It occurs in Word-to-HTML conversion, too. The testing Word document is attached.

using (var outStream = new MemoryStream())
{
    var documentBytes = GetDocumentBytes();
    using (var ms = new MemoryStream(documentBytes))
    {
        var doc = new Aspose.Words.Document(ms);
        var options = new Aspose.Words.Saving.HtmlSaveOptions(Aspose.Words.SaveFormat.Mhtml);
        doc.Save(outStream, options);

        return outStream.ToArray();
    }
}

Message: A generic error occurred in GDI+.
Stack Trace: at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at Aspose.Words.Drawing.Shape.[1](Document [1], 

, Double , Double )
at [1] . 

(OfficeMath <span style="font-size:11.0pt;mso-bidi-font-size:10.5pt;font-family:"Calibri","sans-serif"; 
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-bidi-font-family:
"Times New Roman";mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;
mso-fareast-language:EN-US;mso-bidi-language:AR-SA">[1])
at [1] .(OfficeMath [1], ​ 

)
at [1] .[1](OfficeMath [1], ​ 

)
at ​ .VisitOfficeMathStart(OfficeMath [1])
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at ​ .[1](​ [1])
at spose.Words.Document.[1](Stream [1], String , SaveOptions )

Hi Vadym,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for .NET 15.12.0 and have not found the shared issue. Please make sure that you are using the same document for testing.

Could you please share your environment detail e.g Operating system, .NET Framework etc? We will test the scenario and share our finding here for your reference.

Hi Tahir,

Thanks for your quick response. Our web application is deployed onto a server running Windows 2008 R2 SP1 with .Net Framework 4.5.1 and IIS 7.
As I mentioned before, the exception is intermittent and is difficult to reproduce consistently. However, its impact is significant causing us to recycle the application pool on the web server every time it occurs. We were able able to reproduce it using the testing document uploaded.

Please advise should you require more detail.

Hi Vadym,

Thanks for sharing the detail. We have tested the scenario at Windows 2008 R2 and have not found the shared issue. Please make sure that you are using the latest version of Aspose.Words for .NET 15.12.0 and using the same input document. We have attached the output documents with this post for your kind reference.