Monday, September 1, 2014

Apache PDFBox

Apache PDFBox open source.

I came across this open source, when i wanted to split PDF based on the number pages.

PDFBox is a easy to use opensource library for merging, spliting PDFs which is available for free under Apache license.

If you want to split the large PDF using the PDF box without writing any code.you can use the command line tools of the same library

http://pdfbox.apache.org/commandline/

Download the pdfbox libraries, and follow the instructions.
It can encrypt, decrypt, extrtact text from pdf, etc.

To split below is the command

 java -jar pdfbox-app-x.y.z.jar PDFSplit [OPTIONS] <PDF file>


To code in java for creating a blank pdf document, below is the code.
------------------------------------
import java.io.IOException;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
public class EntryClass {
public static void main(String args[])
{
try {
PDDocument document= new PDDocument();
PDPage blankPage = new PDPage();
document.addPage(blankPage);
document.save("FirstPage.pdf");
if(document!=null)
{
document.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (COSVisitorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    }
}

OUTPUT:
Creates a blank page
----------------------