Free Support Forum - aspose.com

Stamp Document No Show Stamp

Hello,

I’m trying to add a stamp in the upper right corner to PDF files but with some I have the problem that it doesn’t display.

This is the code I’m using:
public static byte[] StampDocument(byte[] document, byte[] stamp)
{
using MemoryStream memoryStreamToPdf = new MemoryStream();
PdfFileStamp pdfDocument = new PdfFileStamp();

            using MemoryStream memoryStreamReader = new MemoryStream(document);
            pdfDocument.BindPdf(memoryStreamReader);

            var stampCreated = CreateStamp(stamp);
            using MemoryStream memoryStreamReaderStamp = new MemoryStream(stampCreated);

            Stamp imageStamp = SetImageStamp(memoryStreamReaderStamp, pdfDocument.PageHeight, pdfDocument.PageWidth);
            pdfDocument.AddStamp(imageStamp);
            pdfDocument.Save(memoryStreamToPdf);

            return memoryStreamToPdf.ToArray();
        }

private static byte[] CreateStamp(byte[] stamp)
        {
            using MemoryStream memoryStreamReaderStamp = new MemoryStream(stamp);
            using Bitmap bitmap = (Bitmap)Image.FromStream(memoryStreamReaderStamp);
            using Graphics graphics = Graphics.FromImage(bitmap);
            using Font arialFont = new Font("Arial", 8);
            using SolidBrush brush = new SolidBrush(Color.FromArgb(4, 4, 126).ToRgb());

            using MemoryStream stream = new MemoryStream();
            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            return stream.ToArray();
        }

private static Stamp SetImageStamp(Stream stamp, double pageDocumentHeight, double pageDocumentWidth)
        {
            int originX = Convert.ToInt32(pageDocumentWidth - 110);
            int originY = Convert.ToInt32(pageDocumentHeight - 80);

            Stamp imageStamp = new Stamp();
            imageStamp.BindImage(stamp);
            imageStamp.SetImageSize(100, 65);
            imageStamp.SetOrigin(originX, originY);
            imageStamp.Pages = new[] { 1 };
            return imageStamp;
        }

I cann’t attach the file because it has sensitive data.

A greeting,

@i.salazar

You can please share your sample file in a private message where only Aspose staff will have access to it. You can send it by clicking over username and pressing Blue Message Button.

I have send to you the file.

@i.salazar

We were able to notice the issue in our environment and it seems like your PDF already has images and stamp is being added behind existing image. Nevertheless, we have logged an issue as PDFNET-48762 in our issue tracking system for further investigation on this case. We will look into its details and keep you informed with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

PS: We tested the scenario using Aspose.PDF for .NET 20.9.

OK, asad.

Thanks for your attention.
Is there any possibility to tell my stamp to overlay the images of the current PDF?

@i.salazar

We already tried setting Background property of ImageStamp as false but it did not give us much success. We are afraid that we cannot offer any alternatives at the moment before the logged ticket is investigated completely. We will let you know as soon as we have some definite updates in this regard. Please give us some time.

We are sorry for your inconvenience.