Manipulate text and images in an existing PDF File

Skip to end of metadata
Go to start of metadata

The PdfContentEditor class allows you to work with text and images in an existing PDF file. In this topic, we'll see how to replace text in a PDF file. We'll see how to replace text on a particular page.

The PdfContentEditor class also allows you to replace a particular image on a specific page. The existing images can also be deleted using the PdfContentEditor class. You can either delete all the images or images with specified indices.

The following sample code shows you how to replace text and images and delete images.

\Java
//create PdfContentEditor object to manipulate contents
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf("input.pdf");
//replace text in the PDF file
editor.replaceText("Source String","Destination String");

//replace text at a specified page
editor.replaceText("Source String", 1, "Destination String");

//replace image
editor.replaceImage(1, 2, ".\\aspose-logo.jpg");

//delete all images
editor.deleteImages();

//delete images with specified indices
int[] index1 ={ 1, 2, 3, 4 };
editor.deleteImages(1, index1);
//save the output file
editor.save("output.pdf");
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.