basically allow a user to label specific text in a pdf file. Use the label information to create a template, which a script uses to extract text from specific pdf.

What would be a good pattern to use in such situation? For example, maybe the script that uses the templates might work for a group of well formatted pdfs but not so with badly formatted pdfs. To optimize for those latter cases, you end up modifying the script which in turn ends up breaking other previously working pdfs. So you fix the script until it finally works on all the pdfs but only the ones you've seen and have been able to create templates for. You hope that eventually you will reach a script that will handle largely varying type of pdfs. It feels like a cat and mouse game and I'm thinking maybe there's a better way to go about doing this.

The other issue that comes up is how to organize code in such scenario. But more importantly, I'm looking for advice on how to tackle the difficult problem of extracting data from pdf using a template based system (or is template system not efficient here?).

  • 1
    Print to an image then OCR? (That might be a joke. I've been in your shoes and I do not envy you). Try using someone else's tool (Acrobat?) to do the text extraction. It's messy. Sep 16, 2014 at 15:24
  • I am trying to write a tool that does that in order to learn the process. OCR could work too
    – user299709
    Sep 16, 2014 at 17:44

1 Answer 1


This depends a great deal on the nature of the PDFs you accept as input. If you have control over the format of the PDF you're accepting, you can very easily extract the data you need; on the other hand, if you agree to accept any valid PDF at all, your task will be much harder.

A loose hierarchy of options that PDFs can provide:

  • PDF forms are designed for the scenario you describe; several toolkits and web services are available for extracting info from PDF forms
  • Structured PDF is a more general way for tagging specific pieces of information in a PDF
  • Even without forms or tags, several toolkits allow you to extract text from a PDF, unless...
  • The PDF only contains images of pages of text, in which case your only hope is an OCR system

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.