How to extract data out of a PDF
This article explains three tools to extract data tables out of PDFs: The open-source tool Tabula and the commercial tools smallpdf and cometdocs.
Often, our data doesn't come in a neat Excel sheet or csv, but is buried as a table in a PDF, like this:
If we then try to copy and paste the numbers from there into a spreadsheet, the columns and/or rows won't translate:
There are many tools out there that try to solve this problem. Every PDF table is a bit different (some are over-designed, some use weird text formations), so if one solution doesn't work for your specific PDF, you can try another one. The first tool we'll show you that lets you extract data tables out of PDFs is Tabula:
Solution 1: Tabula
Tabula is a small open-source software that you can download on your Windows or Mac. Once you installed it and clicked on the tool icon, it will open in your browser, like Firefox or Chrome. But don't worry: All your data will be processed on your computer. Tabula is therefore great for sensitive data.
That's what you will see when you open Tabula:
Click on "Browse" and then "Import" to open the PDF with the data table you want to extract.
Don't upload the full PDF but just the page(s) that contain your data tables.
If your PDF is full of heavy images or hundreds of pages long, any tool will have a hard time handling it. Many PDF readers like Preview on Mac or Adobe Acrobat let you save one or multiple pages of a PDF individually. Make use of that if your chosen PDF extraction tool performs slowly.
After importing your PDF, you can now tell Tabula where the table(s) are on your page(s). To do so, you can click and drag a selection. If you then click on "Preview & Export Extracted Data", you will see how Tabula interpreted your selection:
Have a close look at this preview of your data. Sometimes, some characters of text are missing, and only half of your numbers are right. If your data doesn't look as intended, you have two options:
1. In the sidebar, toggle between "Stream" and "Lattice". Stream looks for whitespace between columns, while Lattice looks for boundary lines between columns. Choosing Lattice instead of Stream or the other way round can make a huge difference.
2. Revise and experiment with your selection. Often, it works well to draw the selection box very close to the data; even within the table. It works worse to select the table and some white space around it. If your preview doesn't get better, try selecting a subset of your data table.
Once your data looks well, you can export it as a csv, tsv or JSON, or just copy and paste the table into your spreadsheet. It's very likely that you still need to clean up the data a bit. Here, we remove the spaces in the numbers. After doing so, we can copy and paste the result in Datawrapper.
Solution 2: smallpdf
If you can't or don't want to install software on your computer and your documents are not sensitive, Smallpdf can be a good solution. It's a PDF converting software that you can use for free online (twice an hour). You can also download it as a free trial.
To use the online version, go to https://smallpdf.com/pdf-to-excel and drag your PDF file in the big green box:
Wait for a second, and your file will be ready for download. Since smallpdf did not ask us to make a selection, like Tabula did, the complete page(s) that we uploaded will be converted.
We get an Excel file with two tabs in it: In the first one we find the text that was placed next to the table in our original PDF; in the second tab we find the table; even in the original design.
Solution 3: cometdocs
If you want to online convert more than two PDFs at once and you don't have a problem with signing up for a service, cometdocs can be a good alternative. It lets you convert five PDFs per week. When you go to their website (cometdocs.com), you will see an "Upload"-Button. Click on it to choose your PDF:
Once your PDF uploaded, it will appear in the white box. Below it, you'll see four tabs. Click on "convert" and drag your PDF there. Then click on your desired output format (Excel, in our case). To start converting your PDF, you know need to sign up:
After a minute or two, you will receive an email with a link to the converted file. Our Excel file will have all the information on one sheet:
Like smallpdf, cometdocs converts the whole page(s) to an Excel file. We will need to do some clean-up here and delete some rows and columns.
There are more than these tools out there to extract data from PDFs. So if none of these options worked for you, it's worth it to search a bit around. If you're a fan of the command line, tools like pdftk might be interesting for you. If you find a better (free and/or open-source) tool than the ones we explained here, do let us know!