Am 11.11.2015 um 06:37 schrieb Nasir Rasul:
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
do this:
private static final String pdfFile = "C:/your directory/name-of-your-file.pdf";
You are this guy, are you?
https://stackoverflow.com/questions/33575548/pdfbox-image-rotation-from-90-to-0
I wrote a comment there... this is not to put you down. You should
really learn java basics first before starting with something as complex
as PDF.
Tilman
Cheers
Nasir
- Nasir
On Tue, Nov 10, 2015 at 6:27 PM, Ronald DERAMUS <[email protected]>
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)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]