I’ve been working at the Guardian this week and was faced with an important dataset that happened to be in PDF format. While PDFs look pretty, they’re all but useless for data journalists.
You can’t copy and paste PDF tables into a spreadsheet. Try it and you’ll end up with something that looks like this:

Pasting a PDF into a spreadsheet will result in random cell merging, odd spacing and a lot of unnecessary work.
Why organisations insist on the more labour-intensive task of formatting their data this way rather than as a spreadsheet, I don’t know, but it is what it is and it’s an obstacle that there are ways around.
The obvious and easiest way to convert a PDF to a .csv or .xls file is to use one of the many free online conversion services. Simon Rogers at the Guardian suggested PDFtoExcelOnline.com, which is a free version of the more powerful conversion software made by Nitro.
The data I was looking at was released by the United Nations High Commissioner for Refugees. It was a series of yearly reports outlining the number of refugees from every country in the world, from 2003 to 2011. That’s nine lists each of well over 200 rows of data.
The online service is great, and the data generally comes back in a coherent form that requires some, but not much, tinkering with to clean it up. Unfortunately, two of the reports could not be converted. With the free service this sometimes just happens. For whatever reason, the converter just doesn’t like the file being uploaded.
I was left with only two options. The first was to input the data I wanted, manually, into a spreadsheet. Considering the size of the dataset it just wasn’t an option. The second route to take was to make a .csv out of the PDF myself. It turns out that, using the method I’m about to explain, a 200+-row table can be converted in a .csv, ready to use in Excel or Google Spreadsheets, in around five minutes.
Click on one of the thumbnails below to view a slideshow of exactly how I did this.
- STEP 1: Open your PDF
- STEP 2: Highlight and copy the data you want. Note that I’ve ignored the column headings. The cell merging here will complicate things and it will be quicker if I just enter them manually once the spreadsheet is created
- STEP 3: Paste your data into a Google Doc.
- STEP 4: Hit CMD+F to bring up the Find and Replace menu. If, like in this dataset, numbers above 1000 are separated by commas (i.e. ‘1,300’) then make sure that the first thing you do is to find all commas and replace with nothing. Make sure that there is not a space in the ‘Replace with’ field.
- STEP 5: Your data should now look like this.
- STEP 6: Now, we’ll find all spaces and replace with commas.
- STEP 7: Your data is now comma-separated. What this means is that Excel or Google Spreadsheets will read commas to denote a new, adjacent cell. However, there’s a bit of cleaning up to be done…
- STEP 8: Any text or values that you want to be separated by spaces will now have been comma-separated, like this country name. At this point, change commas to spaces where applicable.
- STEP 9: Also, the data may have random line breaks in strange places, so hit backspace where necessary to bring everything back into one row. Sometimes, though, a string of characters is too long for one line, but it’s fine if that’s the case.
- STEP 10: Now, each line should denote a row of data in a spreadsheet. Download from Google as a .txt file. NOT an .rtf.
- STEP 11: Open your .txt file in TextEdit. It should look like this.
- STEP 12: As the file is already saved as a .txt, go to File > Duplicate, to create an unsaved version.
- STEP 13: Save this duplicate with the files extension ‘.csv’.
- STEP 14: Open your manually made .csv file in Excel.
- STEP 15: Voila! Here’s your PDF data in a tidy spreadsheet, ready for you to do what you want to it! In this case, I had to repeat the whole process with the three other pages of the PDF and copy the resultant data onto the bottom of this spreadsheet. The whole process with the four pages took 15 minutes.
















Pingback: How to extract data from a PDF - #Interhacktives
Pingback: Pdp’den veri nasıl ayıklanır? - Data Journalism Veri Gazeteciliği - Dağ Medya Yayınıdır | www.dagmedya.net