Hello,

I have some trouble with documents the library is not not able to retreive the number of pages and load them into the list using PDDocument.getDocumentCatalog().getAllPages() method.

The pdf file and the java code to retreive the number of pages are attached to this mail. apparently it's look like the PDFParser do not read correctly the /Pages object the ref of pages are "8 0" and "19 0".

I open the document correctly with adobe reader and itextrups, both retrieve the correct number of pages : 2.

I try to run my code using the version 1.7.0 of PDFBox

Thanks in advance for your help.

Best regards

Pierre Huttin
import java.io.IOException;
import java.util.List;

import org.apache.pdfbox.pdmodel.PDDocument;

public class ListPages
{
        private ListPages()
        {
                //utility class, should not be instantiated.
        }

        /**
         * @param args The command line arguments.
         *
         * @throws Exception If there is an error parsing the document.
         */
        public static void main( String[] args ) throws Exception
        {
                if( args.length != 1 )
                {
                        usage();
                }
                else
                {
                        PDDocument document = null;
                        try
                        {
                                document = PDDocument.load( args[0] );
                                if( document.isEncrypted() )
                                {
                                        throw new IOException( "Encrypted 
documents are not supported for this example" );
                                }
                                List allpages = 
document.getDocumentCatalog().getAllPages();
                                System.out.println("NB Pages : " + 
allpages.size());
                        }
                        finally
                        {
                                if( document != null )
                                {
                                        document.close();
                                }
                        }
                }
        }

        /**
         * This will print the usage for this class.
         */
        private static void usage()
        {
                System.err.println( "Usage: java 
"+ListPages.class.getCanonicalName()+" <input-pdf>" );
        }


}

Reply via email to