2

I have a bunch of pdf files/forms that are all in a standardized format. They contain information such version history, author, who signed the document, and what documents it references. I need to extract that information to feed into a database containing information about the documents. I am pretty sure I could do this using a regular expression(s),but I am not entirely sure how to go about it. I would like to automate the process also, so that when new documents are created, they are added to the system, and also the system looks at all the documents on a web page and extracts the information.

10
  • 1
    On Linux you can use exiftool to extract .pdf metadata and parse its output using regular expressions. For example, to find Creator of a given .pdf: exiftool doc.pdf | grep "^Creator" | perl -pe 's,^Creator.+: (.*)$,\1,'. To find an author: exiftool doc.pdf | grep "^Author" | perl -pe 's,^Author.+: (.*)$,\1,' Jun 25, 2015 at 15:44
  • However, some of the information about the document that I need to extract will not be in the normal metadata. There will be a section of text in the document itself, saying authorized by: "" or References: "". It needs to extract the actual text from the document and extract specific text from that.
    – cluemein
    Jun 25, 2015 at 22:01
  • 1
    It's possible to convert .pdf document to a text file. After doing that it should be possible to extract a piece of text depending on how regular will it be using regular expcessions. You did not specify what OS you are using but on *nix it's possible to automate this using pdftotext command line tool and a combination of grep/sed/cut/awk/perl Jun 25, 2015 at 22:13
  • what would the syntax for that pdftotext command look like when used?
    – cluemein
    Jun 26, 2015 at 18:41
  • Have you every used Linux command line? Use it just it says in man pdftotext: pdftotext [options] [PDF-file [text-file]]. It also says that Pdftotext reads the PDF file, PDF-file, and writes a text file, text-file. If text-file is not specified, pdftotext converts file.pdf to file.txt. If text-file is ´-', the text is sent to stdout.. So, for example: pdftotext <doc>.pdf will produce <doc>.txt in the same directory. Jun 26, 2015 at 20:12

1 Answer 1

3

It's possible to convert .pdf document to a text file. After doing that it should be possible to extract a piece of text depending on how regular will it be using regular expressions. You did not specify what OS you are using but on *nix it's possible to automate this using pdftotext command line tool and a combination of grep/sed/cut/awk/perl.

To download/upload documents from/to a web server you can use scp if SSH access is enabled or lftp, extract metadata locally and push it to a web server. You will need to have a list of documents you already processed. Alternatively, you don't even need to download .pdf from the web server because you can process it directly on the web server or mount a remote directory with sshfs. You can trigger the operation of extracting metadata every time a new .pdf is added using inotify mechanism or some kind of web server callback or execute it regularly using a crontab job.

I am still not sure whether you prefer *nix or Windows. If you prefer the latter, I can't help you because I don't use it.

Your Answer

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

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