Create First PDF Documents
In this section, we have to create an empty PDF document which does not contain any pages. PDDocument class is used to create a PDF document and save() method is used to save the document to our desired location.
Follow the steps below to create a PDF document -
Create an instance of PDDocument class which belongs to the package org.apache.pdfbox.pdmodel. Getting an instance of PDDocument class we are able to create an empty PDF document.
After creating document, we have to save the document to our desired path. save() method is used to save the document. The save() method accepts a string value and passes a path of the document as a parameter.
After completing the task, we need to close the PDDocument class object by using the close() method.
After successful execution, the program will display the following output message.
Now, if we try to open this empty PDF document, it will display the following error message.
Next TopicPDFBox Adding Page