To extract content from a pdf file, I have used below code segment working with 
the iText library. However, for some pdf documents, it throws an exception 
which is shown at below of the code. I donot understand why this exception is 
sent for some document but for some other it is not thrown. Moreover and 
urgently, how can I solve this problem?

        private ArrayList<byte[]> contentOfPdf() {
                PdfReader reader = null;

                PdfDictionary dictionary = null;
                PRIndirectReference reference = null;

                PRStream contentStream = null;
                ArrayList<byte []> byteStream = new ArrayList<byte []>();
                
                try{
                        reader = new PdfReader(this.filename);
                        
                        for(int currentPage = 0 ; currentPage <= 
this.totalPageNumber ; currentPage ++ ) {
                                
                                dictionary = reader.getPageN(currentPage);
                                reference = (PRIndirectReference) 
dictionary.get(PdfName.CONTENTS);
    /*line 166*/            contentStream = (PRStream) 
PdfReader.getPdfObject(reference);
                                
                                byteStream.add( 
PdfReader.getStreamBytes(contentStream) );
                        }
                } catch(Exception e){
                        e.printStackTrace();
                } finally {
                        reader.close();
                }
                
                return byteStream;
        }


**Exception :**

        java.lang.ClassCastException: com.itextpdf.text.pdf.PdfArray cannot be 
cast to com.itextpdf.text.pdf.PRStream
        at pdfCrawler.retrieveContentOfPdf(CrawlerTask.java:166)
        at pdfCrawler.call(CrawlerTask.java:55)
        at pdfCrawler..call(CrawlerTask.java:1)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to