ImageStamp no longer works with png image in PDF/A-1a document

With previous versions of Aspose.Pdf, we used this code to add a logo image to each page in a PDF:

      string sImageUrl = "decisionheaderlogo.png"; 
      if (bAddHeader && !string.IsNullOrEmpty(sImageUrl) && File.Exists(sImageUrl))
      {
        Document pdfDoc = new Document(sTargetFileFullPath);
        ImageStamp imageStamp = new ImageStamp(sImageUrl);
        imageStamp.Height = 50;
        imageStamp.Width = 100;
        //set properties of the stamp
        imageStamp.TopMargin = 10;
        imageStamp.RightMargin = 10;
        imageStamp.HorizontalAlignment = HorizontalAlignment.Right;
        imageStamp.VerticalAlignment = VerticalAlignment.Top;
        //add header on all pages
        foreach (Page opage in pdfDoc.Pages)
          opage.AddStamp(imageStamp);
        //save updated document
        pdfDoc.Save(sTargetFileFullPath);
      }

In Aspose.Pdf version 17.x (I tried 17.6 and 17.7) this no longer works. The image stamp does not appear in the output PDF and an exception is seen in the debugger each time AddStamp is called:

Exception thrown: 'System.Runtime.InteropServices.ExternalException' in System.Drawing.dll

After some hours of experimentation, I found that the ImageStamp feature still works if the image is first converted to bmp:

        using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(sImageUrl))
        using (MemoryStream ms = new MemoryStream())
        {
          bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
          ms.Seek(0, SeekOrigin.Begin);
          Document pdfDoc = new Document(sTargetFileFullPath);
          ImageStamp imageStamp = new ImageStamp(ms);
          imageStamp.Background = false;
          imageStamp.Height = 50;
          imageStamp.Width = 100;
          //set properties of the stamp
          imageStamp.TopMargin = 10;
          imageStamp.RightMargin = 10;
          imageStamp.HorizontalAlignment = HorizontalAlignment.Right;
          imageStamp.VerticalAlignment = VerticalAlignment.Top;
          //add header on all pages
          foreach (Page opage in pdfDoc.Pages)
            opage.AddStamp(imageStamp);
          //save updated document
          pdfDoc.Save(sTargetFileFullPath);
        }

Although this is a good workaround, I see the issue as a new bug in Aspose.Pdf 17.x and I hope it will be fixed in a future version.

Note that the input file is a PDF document generated by Aspose.Words in PDF/A-1a format (our customers generally insist on PDF/A compliance). A colleague found that the problem with the png image stamp does not occur if we do not use PDF/A but the default Pdf15 compliance. When the error occurs, the PDF/A compliance is also lost in the output PDF file.

@gertjaap

Thanks for contacting support.

I have tested the scenario in our environment with the code snippet(s) which you have shared while using Aspose.Pdf for .NET 17.7. I have used one of my sample PDF (PDF/A-1a compliant) files and was unable to observe any issue with the first method. Please note that I have used PNG type of image for ImageStamp as well.

Sometimes, the issue may be related with the specific input document, so we will really appreciate if you can please share your sample PDF document along with the code snippet, which you are using to create it with Aspose.Words. We will test the scenario in our environment and respond you accordingly.

I have collected the relevant files in this zip file:
http://support.decos.nl/gertjaap/Aspose-160436.zip

Contents of zip file:
test.html-input.pdf: input file in PDF/A-1a format generated by Aspose.Words for .NET 16.6
decisionheaderlogo.png: image used in image stamp
test.html-output-failed.pdf: failed output file, png file used as image stamp
test.html-output-corrected.pdf: corrected output file, image converted to bmp before using it in image stamp

You should be able to reproduce the problem with test.html-input.pdf and decisionheaderlogo.png.
Note that I did not reproduce without setting the Aspose license.

@gertjaap

Thanks for sharing relevant document(s).

I have tested the scenario with shared file(s) and observed the issue which you have reported. Hence I have logged this as PDFNET-43072 in our issue tracking system. We will further investigate the reasons behind this issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.