Add Text Stamp to PDF using C#

Create text stamp programmaticaly using Aspose.PDF for .NET Library

How to add Text Stamps to PDF using .NET Library

In order to work with text stamp into PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Add Text Stamp to PDF Document C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Open a PDF document using Document object.
  3. Create Text Stamp and define its properties.
  4. Add the Text Stamp to Page using AddStamp method

Add Text Stamp to PDF with Python

var inputFile = Path.Combine(dataDir, "sample.pdf");
var outputFile = Path.Combine(dataDir, "AddTextStamp_out.pdf");
var pdfDocument = new Aspose.Pdf.Document(inputFile);
var textStamp = new Aspose.Pdf.TextStamp("Sample Stamp")
{
    Background = true,
    XIndent = 100,
    YIndent = 100,
    Rotate = Aspose.Pdf.Rotation.on90
};

textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold | Aspose.Pdf.Text.FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Aqua;
pdfDocument.Pages[1].AddStamp(textStamp);

pdfDocument.Save(outputFile);