Extract text from Linearized PDF by pdfbox

Viewed 46

I am using org.apache.pdfbox.text.PDFTextStripper version 2.0.26. It works good for most PDFs. But It cannot extract text correctly from Linearized PDF: Extracted text

Is there a way to extract text from Linearized PDF by pdfbox or using other tools?

Here is a Linearized PDF example

2 Answers

The problem with your example PDF is not that it's linearized.

The actual problem is that most fonts in your PDF are missing the necessary information for text extraction: They neither have ToUnicode maps nor useful Encodings, and they are Type 3 fonts which prevents the retrieval of additional information from an associated font program or CIDFont dictionary.

In particular such PDFs usually are explicitly generated to prevent text extraction by regular text extractors.

For such PDFs essentially your only option is to try OCR.

Linearized should not be an issue for text extraction but not all plain text is as you may expect, since some constructs cannot be described in plain text. So it is not clear which part you showing in source file but simple PDFtotext seem to not have a problem. I would avoid generic OCR as likely to add errors. Maths formulas are best converted by dedicated equation converters that work their OCR on image snippets. https://mathpix.com/ Snip is the commercial market leader , and few competitors see https://www.sciaccess.net/en/InftyReader/

enter image description here enter image description here

Here we can see the infty isolated svg formula from the pdf and its OCR extracted characters Yj= γEj 1/θ(Ej)θ−1.... which is meaningless for this type of reversal. A copy of math tables or formulas as images is usually the best possible solution otherwise the result is highly likely to be corrupted. Note how some braces are recognized but not some critical ones.

enter image description here enter image description here enter image description here

We can see why that will happen by looking at the outline of that area, looks like CMEX10 is one of the worst defined as text. θ+ γLj 1/θ(Lj)θ−1 enter image description here

Related