Hi,

Cheenu Madan schrieb:
This is the code

*import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;

public class Main {

    @SuppressWarnings("static-access")
    public static void main (String args[]) {
        PDDocument paper = null;

        try {
            paper = new PDDocument();
            paper.load("VirtualSensors.pdf");
            System.out.println(paper.getNumberOfPages());
            paper.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            if (paper != null) {
                try {
                    paper.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
*
Whichever PDF file I use, getNumberOfPages returns 0.
It does not throw a IOException or FileNotFoundException or any other
Exception.
Exactly the same thing happens if I use a URL object or File object.
Any suggestions? I've hit a brick wall googling and trying to figure it why
it isn'
You are hiding (@SuppressWarnings...) the warning which leads to the solution.
The load method is static and will create the needed instance of PDDocument.
Try something like this:

        PDDocument paper = PDDocument.load(pdf);

BR
Andreas Lehmkühler

Reply via email to