Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-1389

Multy thread access to pdf generate erros

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 1.7.1
    • Fix Version/s: None
    • Component/s: Text extraction
    • Labels:
    • Environment:
      Windows/Linux

      Description

      When working with a PDF that need to be accessed by multiple threads and execute operations to extract the text by region, to avoid the waiting time, it give me a few of warnings and exceptions.

      2012-08-17 11:06:23 WARN org.apache.pdfbox.util.PDFStreamEngine - java.lang.NullPointerException
      java.lang.NullPointerException
      at org.apache.pdfbox.util.operator.SetGraphicsStateParameters.process(SetGraphicsStateParameters.java:50)
      at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:556)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:270)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:237)
      at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:217)
      at org.apache.pdfbox.util.PDFTextStripper.processPage(PDFTextStripper.java:448)
      at org.apache.pdfbox.util.PDFTextStripperByArea.extractRegions(PDFTextStripperByArea.java:153)
      at br.com.pol.util.ProcessamentoPagina.run(ProcessamentoPagina.java:58)
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
      at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
      at java.util.concurrent.FutureTask.run(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)

      And the Exception:
      2012-08-17 11:06:24 WARN org.apache.pdfbox.pdfparser.BaseParser - Corrupt object reference
      java.lang.RuntimeException: java.io.IOException: Unknown dir object c=')' cInt=41 peek=')' peekInt=41 16400
      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:257)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:237)
      at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:217)
      at org.apache.pdfbox.util.PDFTextStripper.processPage(PDFTextStripper.java:448)
      at org.apache.pdfbox.util.PDFTextStripperByArea.extractRegions(PDFTextStripperByArea.java:153)

      I´m sure it´s the multi thread access, because if I do not use thread, it work perfectly.

      My code:
      RandomAccess scratchFile = new RandomAccessFile(new File("tmp_"+source), "rw");
      PDDocument document = PDDocument.loadNonSeq(new File(source), scratchFile);

      Separate the pages at 5 threads, run each one at the Executor Service.

      Thanks in advance.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rodrigoferra Rodrigo Ferrari
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: