How to convert a .pdf file to .txt

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

How to convert a .pdf file to .txt

17 Dec 2021, 13:36

I'd preferably use AHK only, I've been searching and I've tried xpdf but I can't seem to get it to do what I want really, I just want to take a pdf file, take the text out, to compare it to something else, the thing I really need is to convert the pdf file to txt, does anyone know how to do this using ahk only? or perhaps guiding me in how to use xpdf correctly

Any help is appreciated!
User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: How to convert a .pdf file to .txt

17 Dec 2021, 13:57

EntropicBlackhole wrote:guiding me in how to use xpdf correctly
My two five-minute video tutorials will guide you in how to use Xpdf:

Xpdf - Command Line Utilities for PDF Files

Xpdf - PDFtoText - Command Line Utility to Convert PDF Files to Plain Text Files

I use it in numerous AutoHotkey scripts. Below is a sample script for you (it converts all the PDF files in the specified folder to text files using the PDFtoText -raw option, but it's simple to change that to whatever output format you prefer):

Code: Select all

SourceFolder:="c:\MyPDFs\" ; set this to whatever folder you want
PDFtoTextEXE:="d:\Xpdf\bin32\pdftotext.exe" ; set this to wherever you put the tool
OutputFormat:="-raw" ; options (see doc): -layout -lineprinter -raw -simple -table (or null for default)
Errors:=""
NumConverted:=0
If (SubStr(SourceFolder,0,1)!="\")
  SourceFolder:=SourceFolder . "\"
Loop,Files,%SourceFolder%*.pdf
{
  PDFfile:=A_LoopFilePath
  RunWait,"%PDFtoTextEXE%" %OutputFormat% "%PDFfile%",,Hide
  If (ErrorLevel!=0)
    Errors:=Errors . PDFfile . "`n"
  Else
    NumConverted:=NumConverted+1
}
If (Errors="")
  Errors:="None"
MsgBox,4096,Done Converting,Number converted: %NumConverted%`n`nErrors converting:`n%Errors%
ExitApp
Regards, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 352 guests