PDFBox Load Existing Document
This section describes how to load PDF document that already exists in our system. By loading the existing document we can perform many operations on it like adding text, removing text, adding an image, removing page etc.
mport java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class LoadingExistingDocument {
public static void main(String args[]) throws IOException {
//Loading an existing document
File file = new File("C:/PdfBox_Examples/sample.pdf");
PDDocument document = PDDocument.load(file);
System.out.println("PDF loaded");
//Adding a blank page to the document
document.addPage(new PDPage());
//Saving the document
document.save("C:/PdfBox_Examples/sample.pdf");
//Closing the document
document.close();
}
}
0 comments:
Post a Comment