pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nasir Rasul <nasir.ra...@gmail.com>
Subject Re: Trying to get rotate to work
Date Wed, 11 Nov 2015 05:37:59 GMT
Hi Ronald,

 You are declaring
>private static final String pdfFile = null;

Subsequently,
>File f = new File(pdfFile);

In between you need to initialize pdfFile with a value. At this point,
pdfFile is null. It has never been assigned a value

Cheers
Nasir


- Nasir

On Tue, Nov 10, 2015 at 6:27 PM, Ronald DERAMUS <ronalddermus@gmail.com>
wrote:

> 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)
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message