Category: Uncategorized

Convert PDF to Text

The QuickPDF tool from Debenu can do a lot – read PDFs, modify existing ones, create new ones line by line, and lots more.

I had a client that was receiving a bank statement as PDF that we needed to input the info to their Foxpro system. With QuickPDF I could read through the PDF file, convert it all to text, and then process the text to do my import. Pretty powerful and pretty easy.

Here’s a sample program that will convert a PDF to a text file using QuickPDF:

* 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.

view raw
PDFToText
hosted with ❤ by GitHub