Utility: Replace PDF
Description
Replace PDF is a Java utility method that swaps specific pages in a PDF document with new pages from other files. Use this utility within a User Defined Java Class step when your workflow needs to assemble or update a multi-page PDF — for example, replacing outdated pages in a report with revised versions. It accepts an input PDF, an array of replacement files (PDF, JPEG, JPG, or PNG) paired with the target page numbers, and writes the result to an output PDF file path.
Example:
Please find the below sample code to access Replace PDF utility method using User defined java class.
import com.automationedge.ps.docedge.utils.*;
//Create utility class object
PDFUtils rpdf = new PDFUtils();
String inputFile = "E:\\Files\\Issues\\replacePDF\\data\\1060 pre estimate_original.pdf";
String outputFile = "E:\\Files\\Issues\\replacePDF\\data\\1060 pre estimate_original_merge.pdf";
String[][] mergeFiles = { { "E:\\Files\\Issues\\replacePDF\\data\\Aadhar1.pdf", "1" },
{ "E:\\Files\\Issues\\replacePDF\\data\\Aadhar2.pdf", "2" }
};
try {
//Call replace PDF method
String outputfilePath=rpdf.replacePDF(inputFile, mergeFiles, outputFile);
} catch (Exception e) {
throw e;
}
Method Input / Output Parameters
| No. | Field Name | Data type | Supported Format | Description |
|---|---|---|---|---|
| 1 | inputfiles | String | Input file path | |
| 2 | mergeFiles | Array | Pdf (Single page), jpeg, jpg, png | Merge file path with page number |
| 3 | outputfile | String | Output file path |