PRTokeniser Exception

View: New views
1 Messages — Rating Filter:   Alert me  

PRTokeniser Exception

by RajaShankar () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
My requirement is i need to parse a PDF document using iText and pattern match a string in that entire PDF document and where ever we find that particular string i need to bookmark that particular word in that particular page of the PDF document.

But when i parse the entire PDF something of 200 pages pdf document in an incosnsitent manner i am getting the below exception. Sometimes its perfectly parses the PDF sometimes the code throws the below exception for some pages and skips it and goes for the parsing of next page in the pdf.

Suggest me please.. Any soultion for the below exception??


Exception:

java.io.IOException: Error reading string at file pointer 4549
        at com.lowagie.text.pdf.PRTokeniser.throwError(Unknown Source)
        at com.lowagie.text.pdf.PRTokeniser.nextToken(Unknown Source)
        at com.idarspoc.bookmark.PdfBookMarker.searchBookMark(PdfBookMarker.java:93)
        at com.idarspoc.bookmark.PdfBookMarker.bookMark(PdfBookMarker.java:263)
        at com.idarspoc.bookmark.PdfBookMarker.main(PdfBookMarker.java:280)

Code Snippet:

<snippet>
private PdfReader reader;

        /*
         *
         * @param InputFile String @param OutputFile String
         */

PdfBookMarker(String inputFile, String outputFile, boolean append) {
try {
reader = new PdfReader(inputFile,"pass".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
public void extractContent(){
int pageNos = reader.getNumberOfPages();
for (int i = 0; i <= pageNos; i++) {
StringBuffer bf = new StringBuffer();
byte[] content = reader.getPageContent(i);
if ((reader != null) && (content != null)) {
PRTokeniser tokenizer = new PRTokeniser(content);
try {
while (tokenizer.nextToken()) {
if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
bf.append(tokenizer.getStringValue());
}
}
} catch (Exception e) {
System.out.println("");
System.out.println(" Exception on "+ tokenizer.getFilePointer());
e.printStackTrace();
}
System.out.println("Content =====>"
+ bf.toString().trim());
}
}
}
</snippet>

Thanks in Advance,
Rajashankar.R
LightInTheBox - Buy quality products at wholesale price