PPTX DOCX XLSX PDF ODP
Aspose.PDF  for Java
PDF

Add Text Stamp PDF via Java

Create Text Stamp with Aspose.PDF using Java APIs.

How to add Text Stamps to PDF Using Java Library

In order to add text stamp into PDF, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
    </repository>
    

 

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>version of aspose-pdf API</version>
    <classifier>jdk17</classifier>
    </dependency>
    

 

Add Text Stamp to PDF Document Java

You need Aspose.PDF for Java 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

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
  • Development environment like Eclipse or IntelliJ IDEA.
  • Aspose.PDF for Java library referenced in your project.
 

Add Text Stamp to PDF - Java.


    // open document
    Document pdfDocument = new Document("input.pdf");
    // create text stamp
    TextStamp textStamp = new TextStamp("Sample Stamp");
    // set whether stamp is background
    textStamp.setBackground(true);
    // set origin
    textStamp.setXIndent(100);
    textStamp.setYIndent(100);
    // rotate stamp
    textStamp.setRotate(Rotation.on90);
    // set text properties
    textStamp.getTextState().setFont(FontRepository.findFont("Arial"));
    textStamp.getTextState().setFontSize(14.0F);
    textStamp.getTextState().setFontStyle(FontStyles.Bold);
    textStamp.getTextState().setFontStyle(FontStyles.Italic);
    textStamp.getTextState().setForegroundColor(Color.getGreen());
    // add stamp to particular page
    pdfDocument.getPages().get_Item(1).addStamp(textStamp);
    // save output document
    pdfDocument.save("TextStamp_output.pdf");
 

About Aspose.PDF for Java API

Aspose.PDF API can be used for PDF document manipulation and parsing within applications. One can create, modify, compress, secure, print or save PDF to TXT, HTML, PCL, XFA, XML, XPS, EPUB, TEX, Images and more formats. Aspose.PDF is a standalone API and it does not depend on any software including Adobe Acrobat.