We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

GDI+ Exception and missing pictures when converting PPTX to PDF

Hi, when creating a PDF-document with Aspose.Slides in our IIS Web-Server we get exceptions after about half a day of operation. There are two phenomena occurring:

  1. sometimes we get a GDI+ Exception from inside your Aspose.Slides Component (see Stacktrace below)
  2. sometimes we don’t get an exception but the images from the presentation are missing, which is even worse, because we can hardly find out whether an error actually occurred. Currently we check the size of the resulting PDF and if it is considerably smaller than the PPTX we assume that this exception occurred.

After recycling of the application pool (our software is hosted in Microsoft IIS) everything works fine for a while; the same document that provoked the error can be generated without errors until the process seems to become corrupt and the same error occurs every time.

Do you have an idea, what could be the reason? We are using AsposeSildes 17.2.0.0.
Do you need further information from us?

Thanks in advance!

This is our Routine to convert Powerpoint Slides to PDF:

    public static byte[] PptxAsPdf(byte[] pptxBytes, bool generatePdfA, PdfFormat pdfFormat, ITrace trace)
    {
        lock (_wordLock)
        {
            Presentation presentation;
            using (var pptxStream = new MemoryStream(pptxBytes))
            {
                presentation = new Presentation(pptxStream, new Aspose.Slides.LoadOptions(Aspose.Slides.LoadFormat.Auto));
            }

            var pdfOptions = new PdfOptions
            {
                SaveMetafilesAsPng = false
            };

            using (var pdfStream = new MemoryStream())
            {
                presentation.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf, pdfOptions);
                return ConvertStreamToPdfA(pdfStream, generatePdfA, pdfFormat, trace);
            }
        }
    }

This is the Exception we sometimes get

=== [MESSAGE:] ‘A generic error occurred in GDI+.’
=== [SOURCE:] ‘System.Drawing’
=== [TARGETSITE:] ‘Void Save(System.IO.Stream, System.Drawing.Imaging.ImageCodecInfo, System.Drawing.Imaging.EncoderParameters)’
=== [CALLSTACK:]
=== at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
=== at 
.€ .Œ(Image image, Stream stream)
=== at 
.€ .[1] (Stream stream)
=== at ”•[1].Ž–[1]…ctor(™•[1] context, brush)
=== at ”•[1].¬–[1].’( brush, ™•[1] context)
=== at ”•[1]. –[1]. ‘( brush)
=== at ”•[1].ˆ–[1]. Ž( brush, Boolean isStroking)
=== at ”•[1].–[1].‘(†˜[1] path)
=== at •[1].†˜[1].ˆ‰(Ž•[1] visitor)
=== at •[1].˜[1].ˆ‰(Ž•[1] visitor)
=== at •[1]. ˜[1].ˆ‰(Ž•[1] visitor)
=== at •[1].˜[1].ˆ‰(Ž•[1] visitor)
=== at •[1].„˜[1].ˆ‰(Ž•[1] visitor)
=== at ™[1].”™[1].SaveToPdf(PresentationEx pres, Stream stream, PdfOptions options)
=== at Aspose.Slides.Pptx.PresentationEx.Save(Stream stream, SaveFormat format, SaveOptions options)
=== at Lpa.DocFramework.AsposeWrapper.PdfUtils.PptxAsPdf(Byte[] data, Boolean genPdfA, ITrace trace)

@mheuer,

I have observed the information shared by you and suggest you to please try using Aspose.Slides for .NET 17.7 on your end first. If there is still an issue then please share the working sample project along with source presentation creating the issue on your end. I also suggest you to please set the stream position to 0 before saving to file.

Thank you for your these suggestions. Unfortunately this problem happens only in the testing environment of one of our clients. We tried to reproduce this on our developement machines, but didn’t succeed. Is it possible that Server Hardware needs to fulfill certain requirements to be able to convert to PDF in a load situation?

Can I attach or send You some example presentations where the error happens? Maybe you can glean some information from them together with the exception stack trace.

BTW: This is the ConvertStreamToPdfA Method missing from the Code above, but actually the Exception happens before the PDF-A Generation as you can see from the Stack trace, so it should not be relevant:

    private static byte[] ConvertStreamToPdfA(MemoryStream pdfStream, bool generatePdfA, PdfFormat pdfFormat, ITrace trace)
    {
        pdfStream.Flush();
        if (!generatePdfA)
        {
            return pdfStream.ToArray();
        }

        var pdfDocument = new Document(pdfStream);
        return ConvertDocumentToPdfA(pdfDocument, pdfFormat, trace);
    }

    public static byte[] ConvertDocumentToPdfA(Document pdfDocument, PdfFormat pdfFormat, ITrace trace = null)
    {
        byte[] pdfConversionLogBytes;
        bool convert;
        using (var pdfConversionLogOutputStream = new MemoryStream())
        {
            convert = pdfDocument.Convert(pdfConversionLogOutputStream, pdfFormat, ConvertErrorAction.Delete);
            pdfConversionLogBytes = pdfConversionLogOutputStream.ToArray();
        }

        string pdfConversionLog;
        using (var ms = new MemoryStream(pdfConversionLogBytes, false))
        {
            var xElement = XElement.Load(ms);
            pdfConversionLog = xElement.ToString();
        }

        if (!string.IsNullOrEmpty(pdfConversionLog))
        {
            trace?.Info("Messages from conversion of 'PDF' to '{3}' (Aspose.Pdf.Document.Convert() returned: '{0}'):{1}{2}{1}",
                convert, Environment.NewLine, pdfConversionLog, pdfFormat);
        }

        using (var pdfOutputStream = new MemoryStream())
        {
            pdfDocument.Save(pdfOutputStream);
            return pdfOutputStream.ToArray();
        }
    }

@mheuer,

I have observed the elaboration and sample code shared by you. In your sample code I am able to observer Aspose.PDF related code and not related to Aspose.Slides. Secondly, I also request for a working sample Visual Studio project along with source presentation to reproduce the issue on our end. As you have mentioned that this issue is happening on one of your client’s machine. It is also possible that on your client machine there may be be some restriction on writing or saving files on location where he is trying to save exported document.

Hi again, we have upgraded our Client to Version 17.7 and the Problem has not occurred within the last week.
So let’s hope it is resolved for good.
Thank you and best Regards…

@mheuer,

Its pleasing to know that with use of new version things are working on your end. Please feel free to share if there is any issue incurring on your end.