| This article will help you view the PdfContentEditor class in a broader sense. After reading this article, you’ll be able to have a better idea that what kinds of features are supported in this class. It’ll also point you to the right direction regarding the usage of this class. |
Explanation
PdfContentEditor class allows you to manipulate variety of contents. It helps you create different annotations; twenty four annotation types are supported in Aspose.Pdf.Kit for Java. We’ll show you a simple example to help you understand how the variety of annotations can be added in a PDF file.
PdfContentEditor class allows you to manipulate variety of contents. It helps you create different annotations; twenty four annotation types are supported in Aspose.Pdf.Kit for Java. We’ll show you a simple example to help you understand how the variety of annotations can be added in a PDF file.
[Java]
//create PdfContentEditor class PdfContentEditor editor = new PdfContentEditor(); //create rectangle object Rectangle rectangle = new Rectangle(100, 100, 20, 20); //bind input PDF file editor.bindPdf("input.pdf"); //create any annotation - in this case Text Annotation editor.createText(rectangle, "Welcome to Aspose", "You are welcome to Aspose!", true, "Key", 1); //save output editor.save("output.pdf");
It also allows you to change and get viewer preferences as shown in the code snippet given below.
[Java]
//create PdfContentEditor object PdfContentEditor editor = new PdfContentEditor(); //bind input PDF file editor.bindPdf("input.pdf"); //change Viewer Preferences editor.changeViewerPreference(ViewerPreference.HideMenubar); //get viewer preference int preferenceValue = editor.getViewerPreference(); //save output PDF file editor.save("output.pdf");
You can also set the document level JavaScript as shown in the following code snippet.
[Java]
//create PdfContentEditor object to add additional document actions PdfContentEditor editor = new PdfContentEditor(); //open input PDF file editor.bindPdf("input.pdf"); //set script for additional action editor.addDocumentAdditionalAction(PdfContentEditor.DOCUMENT_OPEN, "app.alert('Welcome to Aspose.');"); //save output PDF file editor.save("output.pdf");
This class also helps you replace text and images.
[Java]
//create PdfContentEditor object PdfContentEditor editor = new PdfContentEditor(); //bind input PDF file editor.bindPdf("input.pdf"); //replace text editor.replaceText("source string", "destination string"); //replace image editor.replaceImage(1, 1, "test.jpg"); //save output PDF file editor.save("output.pdf");
You can also delete either all the images or the images on particular index at a particular page.
[Java]
//create PdfContentEditor object PdfContentEditor editor = new PdfContentEditor(); //bind input PDF file editor.bindPdf("input.pdf"); //delete particular images editor.deleteImages(1, new int[] { 1, 4 }); //or - delete all images editor.deleteImages(); //save output PDF file editor.save("output.pdf");
Conclusion 
In this article, we had a look at various features of the PdfContentEditor class. We have also seen that how easy it is to use these features for content manipulation.
| In this article, we had a look at various features of the PdfContentEditor class. We have also seen that how easy it is to use these features for content manipulation. |
