Stamping Like Acrobat

I have a pdf file I want to use as a stamp. I’m not sure what the best approach is. Should I convert it to an image and draw it on the document? or what is the best method so it looks and acts like a stamp that acrobat would apply.

Hi Dave and sorry for the late response.

GemBox.Pdf currently doesn’t support Stamp annotations but it is possible to create them via low-level API.

Here is a code snippet that shows how to do it:

using System;
using System.IO;
using GemBox.Pdf.Content;
using GemBox.Pdf.Objects;

namespace GemBox.Pdf.Test.Quick
{
    static partial class Program
    {
        static void Main()
        {
            var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            // For this code snippet, the PDF file to use as a stamp will be simply a copy of the input PDF file.
            File.Copy(Path.Combine(desktop, "Reading.pdf"), Path.Combine(desktop, "ReadingStamp.pdf"), overwrite: true);

            using (var document = PdfDocument.Load(Path.Combine(desktop, "Reading.pdf")))
            {
                PdfForm stampForm;

                // Convert first page of the PDF file you want to use as a stamp to a form.
                using (var stampDocument = PdfDocument.Load(Path.Combine(desktop, "ReadingStamp.pdf")))
                    stampForm = stampDocument.Pages[0].ConvertToForm(document);

                // Use stampForm.SetBoundingBox() and stampForm.Transform if you want to crop or transform (for example, scale) stamp form.

                var page = document.Pages[0];

                // Get or add the underlying Annots array to the page object via low-level API.
                var annots = page.Annotations.GetArray(getOrAdd: true);

                // Create Stamp annotation dictionary.
                var stampAnnot = PdfDictionary.Create(
                    new PdfDictionaryEntry("Subtype", PdfName.Create("Stamp")),
                    new PdfDictionaryEntry("Rect", PdfArray.Create(PdfNumber.Create(100), PdfNumber.Create(200), PdfNumber.Create(300), PdfNumber.Create(400))),
                    new PdfDictionaryEntry("P", page.GetDictionary().Indirect));

                // Add Stamp annotation dictionary to the Annots array as an indirect object.
                annots.Add(PdfIndirectObject.Create(stampAnnot));

                // Access the last annotation via high-level API.
                var stampAnnotation = page.Annotations[page.Annotations.Count - 1];

                // Set the appearance of the Stamp annotation.
                stampAnnotation.Appearance.Set(stampForm);

                document.Save(Path.Combine(desktop, "ReadingStamped.pdf"));
            }
        }
    }
}

The file used in this code snippet you can download from our example Read text from PDF files with C# / VB.NET applications

Regards,
Stipo