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

Free Support Forum - aspose.com

Stamp not visible in some cases with IsBackground = true

We are trying to put (image and/or text) stamps on different pdf files:

  • when using IsBackground = false => Ok
  • when using IsBackground = true => with some pdfs the stamp is visible, with some other pdfs it isn’t

We are using Aspose.PDF for NET v. 18.12 and this is our code:

    private static Stream ApplyImgStamp(Stream inputStream, Stream inputStampStream)
    {
        Stamp stamp = new Stamp();
        stamp.SetOrigin(200, 200);
        stamp.IsBackground = true;
        stamp.Opacity = 0.7f;
        stamp.BindImage(inputStampStream);
        PdfFileStamp fileStamp = new PdfFileStamp();
        fileStamp.BindPdf(inputStream);
        fileStamp.AddStamp(stamp);
        var stream = new MemoryStream();
        fileStamp.Save(stream);
        fileStamp.Close();
        return stream;
    }

Can you support us?
Thanks

How can I add attachments to post?
Best regards

@fcampanale

Thanks for contacting support.

Please note that IsBackground Property when set to true, causes stamp to render in the background of original content inside PDF Page. In other words, the stamp will be rendered beneath the main layer of content. You may please set this property as false and specify opacity for stamp to render it properly. In case of further assistance, please feel free to let us know.

In case you need to upload files with post for further query, you may upload it using button shown in screenshot. Upload_Files.png (8.9 KB)

Here are the test files:
stamp.png -> the image used as stamp
test1.pdf -> first pdf test file
test2.pdf -> second pdf test file

Then:

  • placing the stamp on first pdf test file (IsBackground = true) => the stamp is not visible
  • placing the stamp on second pdf test file (IsBackground = true) => the stamp is visible

I would expect the same behaviour on both files, but it’s different.
Moreover, if I am forced to specify IsBackground = false, when it makes sense to use IsBackground = true?

Thanks for the attention,
best regards


test2.pdf (42.8 KB)
stamp.png (1.1 KB)
test1.pdf (169.3 KB)

@fcampanale

Thanks for getting back to us.

We have tested the scenario in our environment while using following DOM based code snippet.

Document pdfDocument = new Document(dataDir + "test1.pdf");
ImageStamp imageStamp = new ImageStamp(dataDir + "stamp.png");
imageStamp.Background = true;
imageStamp.Opacity = 0.5;
imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Center;
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
    pdfDocument.Pages[i].AddStamp(imageStamp);
}
pdfDocument.Save(dataDir + "ImageStamp_out1true.pdf");

The stamp is not visible when IsBackground is set to true in test1.pdf because other images are present inside the PDF and due to background property, the stamp is layed at the bottom of images (Stamp.jpg). In case of test2.pdf, there are no images/resources/annotations except plain text so stamp remains visible despite its IsBackground property is set to true.

It is suggested to set IsBackground property as false or leave it unspecified as its default value is also false. Doing this, Stamp would be rendered at the top of content and stay visible in every PDF page. We hope our suggestions are helpful. In case you still face any issue, please feel free to contact us.