16

I am using OSX and would like to be able to convert pdf files to text.

I would like a free application to do this, as I am sure there must be some.

  • 2
    Are you looking to extract text from PDFs which already contain text? (i.e., you could copy and paste pieces out of them) Or are you looking to recognize text that is in image content? – Alan Shutko Nov 7 '14 at 20:31
  • Does free-ocr.com help? – Tim Jan 8 '15 at 15:53
13

Here are the steps I used to install and use xpdf via Homebrew.

  1. Install Homebrew's dependencies:

    xcode-select --install
    
  2. Install Homebrew from their website:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. Do what it tells you to complete the Homebrew installation.

  4. Verify that Homebrew is happy and functioning to spec.

    brew doctor
    
  5. Next install xpdf and its dependencies:

    brew install Caskroom/cask/xquartz
    
    brew install xpdf
    
  6. Finally, use pdftotext, a package that comes with the xpdf suite:

    pdftotext Some_Document.pdf Some_Document.txt
    

The first file name is an existing PDF; the second is the destination. The results were much better than with an (admittedly old) version of Adobe Acrobat. Edit: New (2019) versions of Adobe Acrobat have shown similarly poor results.

6

Multiple methods.

  1. Use Google documents (you will need a Google account)

  2. Use Automator (some work required)

You can use Automator to create a workflow that can extract text from PDFs and save it as a text or RTF document.

extract text from pdf

or an app from the App Store, e.g. PDF to Text

4

xpdf which I installed with ports:

port install xpdf

contains:

xpdf-pdftotext

It does what you want for any PDF file which is coming from a text file (and not from an image):

xpdf-pdftotext PDF_file text_file
  • 1
    The command, at least as installed by HomeBrew, is just “pdftotext”. – Flash Sheridan Feb 23 '16 at 4:12
  • @FlashSheridan Can I encourage you to post an answer covering "pdftotext" and how to install it via homebrew? Comments may get deleted anytime (and also don't show up in searches). – nohillside Feb 24 '16 at 13:39
4

Current version of Adobe Reader (11.0.09) has a "Save as Other" item in its File Menu.

One of the options is Text.

The App is free, and does a decent job outputting text files. All images in the new document will be lost with the .txt format.

1

I would think you should be able to copy and paste the text into another document. To select all the text

Open the PDF in "Preview", and

  • choose "Edit | Select All"
  • choose "Edit | Copy"

Go to another app, say "Text Edit"

  • choose "Edit | Paste"

Note that if you try and do this, and there's no text pasted, just a bunch of blank lines, try printing your PDF to a new PDF first, e.g.

  • In Preview, choose "File | Print"
  • In the bottom right, choose "PDF | Save as PDF"
  • This exports a new PDF.

Now try the above process with this new PDF. Worked for me!

PS: If you have Microsoft Word, you may be able to open your PDF in word

  • 1
    While this should work when the PDF document actually contains text content, it does not maintain formatting and in some cases produces garbage text along with what would be considered wanted text. Note that this may also be the same with other methods, but I felt it important to point out. – user3439894 Oct 24 '17 at 16:53
  • without a doubt - not perfect for sure, and I totally agree with everything you've said. I only add it here as an option I've noticed before, that worked for me without installing anything at all ;-) – Brad Parks Oct 24 '17 at 17:25
  • I also agree that it works for most cases, but page numbers, footer details that aren't related to the document and worse yet: INFINITE SCROLLING on large documents make this an unsatisfactory solution. If it was less than 5 pages I'd consider it, but given most tables I need are from PDFs off research sites that refuse to spit out excel or SQL, this option isn't even functional. – Tmanok Feb 27 at 2:56
  • Agreed! not a viable option for your use case – Brad Parks Feb 27 at 11:18
0

The following python script will output the text from a PDF document to a .txt file. (Note: There is no guarantee that the text is necessarily in 'logical' human readable order, due to the way that data is held in the PDF format.)

The script will create text files for any PDF files supplied as arguments to it on the command line (e.g. pdf2txt.py myPDF.pdf), or you can use in Automator's "Run Shell Script" action, setting the shell type to python and Pass input to "As arguments". Then you can use it as a Quick Action or DropApp.

#!/usr/bin/python
# coding: utf-8

import os, sys
from Quartz import PDFDocument
from CoreFoundation import (NSURL, NSString)
NSUTF8StringEncoding = 4

def pdf2txt():
    for filename in sys.argv[1:]:   
        inputfile =filename.decode('utf-8')
        shortName = os.path.splitext(filename)[0]
        outputfile = shortName+" text.txt"
        pdfURL = NSURL.fileURLWithPath_(inputfile)
        pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
        if pdfDoc :
            pdfString = NSString.stringWithString_(pdfDoc.string())
            pdfString.writeToFile_atomically_encoding_error_(outputfile, True, NSUTF8StringEncoding, None)

if __name__ == "__main__":
   pdf2txt()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .