[ 
https://issues.apache.org/jira/browse/PDFBOX-1757?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13806800#comment-13806800
 ] 

William Palmer commented on PDFBOX-1757:
----------------------------------------

Using the code (still using 1.8.2):
                PDFTextStripper ts = new PDFTextStripper();
                PrintWriter out = new PrintWriter(new FileWriter(new File 
(pFile+".txt")));
                RandomAccess scratchFile = new 
RandomAccessFile(File.createTempFile("pdfbox-", ".tmp"), "rw");
                PDDocument doc = PDDocument.loadNonSeq(new File(pFile), 
scratchFile)
                ts.setForceParsing(true);
                ts.writeText(doc, out); 

The following files (links above) give the following errors:
268346.pdf:
Exception in thread "main" java.io.IOException: Error: Expected an integer 
type, actual='n'
        at org.apache.pdfbox.pdfparser.BaseParser.readInt(BaseParser.java:1622)

020747.pdf:
Exception in thread "main" java.io.IOException: Error: Expected an integer 
type, actual='ref'
        at org.apache.pdfbox.pdfparser.BaseParser.readInt(BaseParser.java:1622)

247224.pdf:
Caused by: java.io.IOException: Unknown dir object c='>' cInt=62 peek='>' 
peekInt=62 3012537
        at 
org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:1334)

To note - I have discovered one problematic test file from the above source 
(not listed above) - is there a way I can easily check if a PDF file is 
corrupt/valid, or not, with PDFBox?

> Errors parsing/extracting text from a PDF
> -----------------------------------------
>
>                 Key: PDFBOX-1757
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1757
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.8.2
>         Environment: Ubuntu Linux & Windows 7 (both JDK6)
>            Reporter: William Palmer
>            Priority: Minor
>
> I am trying to extract text from PDFs.  Extracting text from the test file 
> http://digitalcorpora.org/corp/nps/files/govdocs1/020/020747.pdf causes 
> exceptions to be thrown.
> The first:
> Exception in thread "main" java.lang.RuntimeException: java.io.IOException: 
> Value is not an integer: 636121514401477526485946144
>       at 
> org.apache.pdfbox.pdfparser.PDFStreamParser$1.tryNext(PDFStreamParser.java:187)
>       at 
> org.apache.pdfbox.pdfparser.PDFStreamParser$1.hasNext(PDFStreamParser.java:194)
>       at 
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:255)
>       at 
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:235)
>       at 
> org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:215)
>       at 
> org.apache.pdfbox.util.PDFTextStripper.processPage(PDFTextStripper.java:455)
>       at 
> org.apache.pdfbox.util.PDFTextStripper.processPages(PDFTextStripper.java:379)
>       at 
> org.apache.pdfbox.util.PDFTextStripper.writeText(PDFTextStripper.java:335)
> Caused by: java.io.IOException: Value is not an integer: 
> 636121514401477526485946144
>       at org.apache.pdfbox.cos.COSNumber.get(COSNumber.java:104)
>       at 
> org.apache.pdfbox.pdfparser.PDFStreamParser.parseNextToken(PDFStreamParser.java:351)
>       at 
> org.apache.pdfbox.pdfparser.PDFStreamParser.access$000(PDFStreamParser.java:46)
>       at 
> org.apache.pdfbox.pdfparser.PDFStreamParser$1.tryNext(PDFStreamParser.java:182)
> Code to cause above exception:
> PDFTextStripper ts = new PDFTextStripper();
> PrintWriter out = new PrintWriter(new FileWriter(new File ("020747.txt")));
> PDDocument doc = PDDocument.load(new File("020747.pdf").toURI().toURL(), 
> true);
> ts.setForceParsing(true);
> ts.writeText(doc, out);
> Using the following code causes a different exception until 
> org.apache.pdfbox.baseParser.pushBackSize is increased (only tested 1024768). 
>  After it is increased I get basically the same exception as above
> PrintWriter out = new PrintWriter(new FileWriter(new File("020747.txt")));
> PDFParser parser = new PDFParser(new FileInputStream(new File("020747.pdf")));
> parser.parse();
> PDFTextStripper ts = new PDFTextStripper();
> ts.setForceParsing(true);
> ts.writeText(parser.getPDDocument(), out);



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to