I am trying to convert PDF files to text files using textutil. I don't if there are special types of PDFs that can and cannot be converted. The files I am trying to convert are in a searchable format, which I assume is a minimum requirement. When I convert the file, the text document is completed garbled output. Here is my code:

textutil -convert txt example.pdf

Here are some of the first lines, in case that helps to identify where I am going wrong:

4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>

I'm guessing it has to do with some encoding feature -- not my area of expertise, so any assistance would be greatly appreciated!

  • 1
    Have you tried your luck with poppler's pdftotext/html? Not every PDF can be converted that way. See if you can search for text in the PDF, if that doesn't work then you might have to resort to OCR Mar 31 '15 at 14:59
  • The lines that you show here is the PDF.
    – A.B.
    Mar 31 '15 at 15:45
  • @frostschutz That alternative worked perfectly. After install, I ran pdftotext example.pdf and it produced exactly what I needed. Feel free to suggest in the answer and I will accept!
    – Brian P
    Mar 31 '15 at 16:05

With reference to TEXTUTIL(1) manual page it seems pdf is not between formats managed by this utility: fmt is one of: txt, html, rtf, rtfd, doc, docx, wordml, odt, or webarchive

On Linux/Unix installing a scriptable product like XPDF/pdftotext may be a valid solution like some comment already suggested.

For those on OS X it's possible extract text from PDF by a native OS X automator action ( ..see this answer or last 4' of this tutorial) then consider that automator's workflow can be "scripted" via CLI automator command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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