0

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:

%PDF-1.3
%ƒÂÚÂÎßÛ†–ƒ∆
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
xÌõYè‹∏«flı)8>2”„å,R%Ÿªõ¯fixs9ôM‚<YÅ`„Ô‰W,J¢‘íF3”@^2Z›<ädˇ:(ˇl>òüçuπ´Í¶ñ¶nõº.⁄⁄         
4>~˘œ?Ã_ÕøÕ”W_≠˘Ù’·fl◊OL.ò´øÂKI5ÖÀª∫*≥O_ÃÀk”‘aH|\1OØØù
±Ê˙'sqv0◊ˇ2oÆ√Vñ©˘÷Êmy2jæ»;P+Ú¢(*s˝ikó3>z¸ãõæ8;èè˙΄·ê—z~=|  
¯D˝rËî)WÈå<˝¡ÒˇnÆfl/3¿’UnõÆ4~∫Á;Ú”µ≠J˙4‰JWùîgz8€]êªA@g¸≠kRŸ¯‹÷ùàëeÁÔπUŸÓ÷Ü´≤Œ

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 – frostschutz 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
1

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.