Skip to content

Instantly share code, notes, and snippets.

@paladintodd
Created December 6, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paladintodd/f09c48f7b6877f98510dd1abdd2633f6 to your computer and use it in GitHub Desktop.
Save paladintodd/f09c48f7b6877f98510dd1abdd2633f6 to your computer and use it in GitHub Desktop.
* Ask for a PDF file, grab each page from it, convert to text
* Save resulting text to a pdf.txt file
* Get the file.
PRIVATE lcFile
lcFile = GETFILE("PDF", "Select", "Select")
IF EMPTY(lcFile)
RETURN
ENDIF
* Setup QuickPDF object
PRIVATE loPDF
loPDF = CREATEOBJECT("QuickPDFAX0724.PDFLibrary")
loPDF.UnlockKey("YourUnlockKey")
loPDF.SetMeasurementUnits(1) && Millimeters
loPDF.SetOrigin(1) && Top Left
* Variable for walking through the PDF
PRIVATE loPage, lnPageCnt, lcPageContent, lcText, lnFile
loPage = ""
lnPageCnt = 0
lcPageContent = ""
lcText = ""
* Open PDF
lnFile = loPDF.DaOpenFile(lcFile, " ")
IF EMPTY(lnFile)
MESSAGEBOX("Could not read the PDF file you selected.", 0)
return
ENDIF
* Loop through grabbing each page
DO WHILE .t.
lnPageCnt = lnPageCnt + 1
loPage = loPDF.DAFindPage(lnFile, lnPageCnt)
IF EMPTY(loPage) && No more pages
EXIT
ENDIF
* Convert page object to text
lcPageContent = loPDF.DAExtractPageText(lnFile, loPage, 0)
* Add this page of text to our text variable
lcText = lcText + CHR(13) + CHR(10) + lcPageContent
ENDDO
loPDF.DaCloseFile(lnFile) && Close PDF
STRTOFILE(lcText, "PDF.txt") && Save text we found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment