PDFBox Example | Create Empty PDF file using java PDFBox

by Azeem Tariq

Posted 2 years ago

Last Updated 1 year ago




Hi in the previous tutorial  we set up our development environment for creating pdf files using PDFBox library and in this tutorial i will show you how you can use PDFBox and create very simple and empty PDF file. If you guys did not check my previous post then please check it and follow the steps to proceed in this tutorial

Java PDFBox Example Code

import java.io.IOException;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;

 * @author Azeem
 * @Email [email protected]

public class Main {

    public static void main(String[] args) {
        System.out.println("Create Simple PDF file with blank Page");
        String fileName = "EmptyPdf.pdf"; // name of our file
        PDDocument doc = new PDDocument(); // creating instance of pdfDoc
        doc.addPage(new PDPage()); // adding page in pdf doc file
        doc.save(fileName); // saving as pdf file with name perm 
        doc.close(); // cleaning memory 
        System.out.println("your file created in : "+ System.getProperty("user.dir"));
        catch(IOException | COSVisitorException e){



This is very simple tutorial to create pdf file but if you still face problem then please check out video tutorial :) if you don't like my tutorial then tell me if you like it then tell your friends :)