//create an object of PdfContentEditor class
PdfContentEditor contentEditor = new PdfContentEditor();
//bind input PDF file
contentEditor.bindPdf(“input.pdf”);
//set regular expression mode
contentEditor.getReplaceTextStrategy().setRegularExpressionUsed(true);
//replace string which satisfies to regular expression
contentEditor.replaceText(“\\d{2}\\.\\d{2}\\.\\d{4}”, “New text”);
//save the output file
contentEditor.save(“output.pdf”);
contentEditor.close();
<?xml version=”1.0″ encoding=”utf-8″?>
<fields>
<field name=”Telephone”>
<value>888.277.6734</value>
</field>
<field name=”Name”>
<value>Mike</value>
</field>
<field name=”Lodging”>
<value>Off</value>
</field>
<field name=”Gender”>
<value>Male</value>
</field>
<field name=”Photo”>
<value>c:\files\butterfly.jpg</value>
</field>
</fields>
You can simply import the image file along with other data using the following code snippet:
//create a Form object
Form pdfForm = new Form(“input.pdf”, “output.pdf”);
//create input stream for XML
FileInputStream inStream = new FileInputStream(“data.xml”);
//import data to the PDF form
pdfForm.importXml(inStream);
//close input stream and Form object
inStream.close();
pdfForm.close();
In addition to the above two features, we have improved file encryption, viewer preference, replace text and Form related issues. You can see the complete list of changes and download the latest version from the Aspose.Pdf.Kit for Java download section.