Edit PDF via Java

Advanced PDF Editor for Java. Use Aspose.PDF to modify PDF documents programmatically

How to Edit PDF with Java

Do you need to edit PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With Java libraries like Aspose.PDF, developers can edit text in PDF, insert graphs using external data, modify tables and more. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional Java developers.

  • Edit PDF elements: tables, texts, images,, fields, etc.
  • Edit PDF formatting attributes and styles
  • Add new elements
  • Work with graphs and forms

In order to edit PDF file, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful, and easy-to-use conversion API for the 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 AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

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

How to Edit PDF via Java


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

  1. Design and Develop your editor.
  2. Or use Aspose Editor by accessing its demo app using advanced WYSIWYG editor.
  3. Upload PDF files to edit.
  4. Modify the document with relevant changes.
  5. Save the PDF file.

One of the most requested features is the editing and adding text in PDF. Working with text is very convenient with Java library: edit text, update text and format text using Java. The following example demostrates how to modify a PDF document in Java:

Edit PDF Files - Java

This sample code shows how to edit text in PDF - Java

	public static void ReplaceTextInParticularRegion(){
    // load PDF file
    Document pdfDocument = new Document(_dataDir+"sample.pdf");

    // instantiate TextFragment Absorber object
    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("PDF");

    // search text within page bound
    textFragmentAbsorber.getTextSearchOptions().setLimitToPageBounds(true);

    // specify the page region for TextSearch Options
    textFragmentAbsorber.getTextSearchOptions().setRectangle(new Rectangle(100, 700, 400, 770));

    // search text from first page of PDF file
    pdfDocument.getPages().get_Item(1).accept(textFragmentAbsorber);

    // iterate through individual TextFragment
    for(TextFragment tf : textFragmentAbsorber.getTextFragments())
    {
        // replace text with "---"
        tf.setText("---");
    }

    // Save the updated PDF file
    pdfDocument.save(_dataDir+"Updated_Text.pdf");
}

About Aspose.PDF for Java API

Aspose.PDF for Java API is a library that enables developers to add PDF processing capabilities to their applications. It can be used to build any type of 32-bit and 64-bit applications to generate or read, convert and manipulate PDF files without the use of Adobe Acrobat. Aspose.PDF for Java allows developers to insert tables, graphs, images, hyperlinks, custom fonts - and more - into PDF documents. Moreover, it is also possible to compress PDF. Aspose.PDF for Java provides excellent security features to develop secure PDF files.

You can find more information about Aspose.PDF for Java API on documentation and examples on how to use API. Some of the key features of Aspose.PDF for Java API include support for various file formats including HTML, XFA, TXT, PCL, XML, XPS and image file formats, support for various PDF versions, and extensive hyperlink functionality.