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.
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.
Here are the steps I used to install and use xpdf via Homebrew.
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Do what it tells you to complete the Homebrew installation.
Verify that Homebrew is happy and functioning to spec.
brew doctor
brew install Caskroom/cask/xquartz
brew install xpdf
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.
xquartz
is not needed for the console tools in xpdf
. Furthermore, there is the poppler
fork of xpdf
which seems far more actively maintained: github.com/scraperwiki/scraperwiki-python/issues/…
Sep 18, 2018 at 12:46
Multiple methods.
Use Google documents (you will need a Google account)
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.
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
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.
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()
NB: The above script will 'only' work on any Mac running Leopard to Monterey 12.2...! Python 2 was removed from macOS in Monterey 12.3. If you install python 3 and the pyobjc library, then the following python 3 script will work:
#!/usr/bin/env python3
import os, sys
from Quartz import PDFDocument
from CoreFoundation import (NSURL, NSString)
NSUTF8StringEncoding = 4
def pdf2txt():
for filename in sys.argv[1:]:
shortName = os.path.splitext(filename)[0]
outputfile = shortName+" text.txt"
pdfURL = NSURL.fileURLWithPath_(filename)
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()
if pdfDoc
statement with print(pdfDoc.string())
.
Extract selectable text (not OCR) in PDF on MacOS
brew install poppler
pdftotext x.pdf x.txt
Related: linux - Is the pdftotext command line tool for mac? - Super User
I would think you should be able to copy and paste the text into another document. To select all the text
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.
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