Hi all,
I'm new to this list and to java. I was wondering if anyone has a good
working example of the rotate page feature? I haven't found a good example
and I am trying to rotate a whole pdf page and save it.. I have the
following code but it doesn't seem to work... I'm having a hard time
getting rid of the NullPointer error.

Here is my code:

//import java.awt.List;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;


public class PdfRotator {


     private static final String pdfFile = null;

         public static void main(String[] args) throws IOException {

    PDDocument document = PDDocument.load("PDFrotatorTEST.pdf");



            //public static void main(String[] args) throws Exception {

     List pages = (List) document.getDocumentCatalog().getAllPages();

     for (int i = 0; i < pages.size(); i++) {
         PDPage page = (PDPage) ((java.util.List) pages).get(i);// PDPage
page = (PDPage) pages.get(i);
         if ((i + 1) % 2 == 0) {
             page.setRotation(0);
         }
     }

     File f = new File(pdfFile);// File f = new File(pdfFile);
     String newFile = f.getParent() + File.separator + "out.pdf";
     try {
        document.save(newFile);
    } catch (COSVisitorException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     document.close();
}
}

Errors:
Exception in thread "main" java.lang.NullPointerException
    at java.io.File.<init>(Unknown Source)
    at PdfRotator.main(PdfRotator.java:36)

Reply via email to