5

I have a couple of PDFs which are scanned documents with lots of tables. Take the following image as an example:

I would like to get the tables from the images.

Desired output

A HTML file with <table> tags would be awesome, but even something like what you get from pdftotext -layout would be ok:

                          Single Model Accuracy                    Ensemble of 10
        Dataset
                       Training Set      Test Set              Training Set Test Set
        CIFAR-10      99.99 %    ±0.1    99.99 %    ±0.1           99.99 %   99.99 %
        CIFAR-100     99.99 %    ±0.1    99.99 %    ±0.1           99.99 %   99.99 %
        SVHN          99.99 %    ±0.1    99.99 %    ±0.1           99.99 %   99.99 %
        GTSRB         99.99 %    ±0.1    99.99 %    ±0.1           99.99 %   99.99 %
        HASYv2        99.99 %    ±0.1    99.99 %    ±0.1           99.99 %   99.99 %

Table 1: Baseline model accuracy on five datasets. The single model accuary is the
         10 models used in the ensemble. The range of the accuracies of those models is
         also given.


  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis malesuada efficitur
volutpat. Proin eget dui in lacus fermentum pharetra. Sed ut facilisis leo, sed consectetur
urna. Phasellus eget tempus eros, vitae sagittis mi. Nullam pharetra, dolor a efficitur
blandit, nisl velit interdum turpis, vel posuere lorem justo nec elit. Donec mattis massa
auctor mattis varius. Nunc sed volutpat sapien, at finibus lectus. Phasellus auctor
vehicula auctor. Nam vitae purus ut orci accumsan auctor. Fusce volutpat, tortor
consectetur convallis aliquam, enim velit gravida sapien, id convallis nisi nunc ac leo.

 Country / Property     Population               Area   HDI
 France                     66 · 106     668763km2      0.89
 Germany                    81 · 106     357167km2      0.92
 United States             317 · 106    9629091km2      0.94

                          Table 2: Information about countries

   Aenean sit amet felis eu urna accumsan consectetur. Sed hendrerit ultrices turpis nec
fringilla. Pellentesque sagittis neque placerat, pharetra ante quis, maximus eros. Nam
ultrices lacinia magna, eget interdum tortor ornare ut. Praesent semper tristique con-
sectetur. Sed auctor, orci accumsan imperdiet vestibulum, nunc augue sagittis purus,
sed dapibus neque arcu sit amet enim. Aliquam fermentum dui eu efficitur condimen-
tum. Maecenas viverra metus ut bibendum pellentesque. Integer non interdum massa.
Vestibulum non enim vulputate, sodales nunc ac, ultricies tortor. Suspendisse non ve-
hicula ipsum, quis consequat elit. Quisque rutrum tincidunt lorem id semper. Phasellus
bibendum nulla sit amet purus tempus, vitae tincidunt ligula ornare. Nunc quis felis
non ex consequat elementum nec sit amet magna. In lacinia nulla nec neque venenatis,
vel tristique risus blandit.




                                             1

Non-working OCR engines

tesseract

tesseract table-test.jpg output -l eng gives me the following:

Dataset Single Model Accuracy Ensemble of 10





Training Set Test Set Training Set Test Set
CIFAR—lO 99.99 % ::0.1 99.99 % ::0.1 99.99 % 99.99 %
CIFAR—lOO 99.99 % ::0.1 99.99 % ::0.1 99.99 % 99.99 %
SVHN 99.99 % ::0.1 99.99 % ::0.1 99.99 % 99.99 %
GTSRB 99.99 % ::0.1 99.99 % ::0.1 99.99 % 99.99 %
HASYv2 99.99 % ::0.1 99.99 % ::0.1 99.99 % 99.99 %

Table 1: Baseline model accuracy on five datasets. The single model accuary is the
10 models used in the ensemble. The range of the accuracies of those models is
also given.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis malesuada efficitur
volutpat. Proin eget dui in lacus fermentum pharetra. Sed ut facilisis leo, sed consectetur
urna. Phasellus eget tempus eros, vitae sagittis mi. Nullam pharetra, dolor a efficitur
blandit, nisl velit interdum turpis, vel posuere lorem justo nec elit. Donec mattis massa
auctor mattis varius. Nunc sed volutpat sapien, at finibus lectus. Phasellus auctor
vehicula auctor. Nam vitae purus ut orci accumsan auctor. Fusce volutpat, tortor
consectetur convallis aliquam, enim velit gravida sapien, id convallis nisi nunc ac leo.

Country / Property Population Area HDI
France 66 - 106 668763km2 0.89
Germany 81 - 106 357167km2 0.92
United States 317 - 106 9629091km2 0.94

Table 2: Information about countries

Aenean sit amet felis eu urna accumsan consectetur. Sed hendrerit ultrices turpis nec
fringilla. Pellentesque sagittis neque placerat, pharetra ante quis, maximus eros. Nam
ultrices lacinia magna, eget interdum tortor ornare ut. Praesent semper tristique con—
sectetur. Sed auctor, orci accumsan imperdiet vestibulum, nunc augue sagittis purus,
sed dapibus neque arcu sit amet enim. Aliquam fermentum dui eu eflicitur condimen—
tum. Maecenas viverra metus ut bibendum pellentesque. Integer non interdum massa.
Vestibulum non enim vulputate, sodales nunc ac, ultricies tortor. Suspendisse non ve—
hicula ipsum, quis consequat elit. Quisque rutrum tincidunt lorem id semper. Phasellus
bibendum nulla sit amet purus tempus, vitae tincidunt ligula ornare. Nunc quis felis
non ex consequat elementum nec sit amet magna. In lacinia nulla nec neque venenatis,
vel tristique risus blandit.

As you can see it recognizes the text, but the the information about the table is completely lost.

2 Answers 2

2

A combination of tools does the job:

  1. ocrmypdf
  2. pdftotext with the -layout flag
  3. a self-written script

Installation for Ubuntu

sudo apt-get install pdftotext ocrmypdf
2
  • 1
    Funny side-note: Did you see that ocrmypdf uses Tesseract for the OCR operation (which did not work out for you stand-alone)? Must be the positioning and subsequent formatting by pdftotext then what did the trick. Nice find! If your script isn't too big, putting it into a pastebin/Gist and linking it to your answer might be a good idea. Please also point out compatibility (here: Linux/Unix & Mac are supported), and how to install pdftotext (simple apt-get, I know – but others might not).
    – Izzy
    Aug 16, 2017 at 16:20
  • The installation for pdftotext no longer works. Is there another piece of software that works well for this? I'm quite interested in extracting some tables from a PDF of a scanned image. Thanks! Oct 10, 2017 at 13:57
0

You can try to use a paid software like FoxIT Phantom PDF Standard which does the job.

FoxIT Phantom PDF has an OCR function. You can buy a license for 109$ or rent it for 7.50$ per month. So I guess you can do your job with 7.50$ in a month if you have a low number of documents.

Note: FoxIT is behind Chrome PDF Reader and other pdf tools (reference).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.