Visual Basic 6.0 Requires Chilkat v11.7.0+
Visual Basic 6.0
Extract Text from a PDF
See more PDF Text Extraction Examples
Demonstrates the simplest way to extract the text of a PDF: the "text" operation with default options returns the text of all pages as flowing paragraphs, together with a quality report that says whether the text can be trusted.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
' The two-page PDF used in this example is available at two_page_memo.pdf
Dim pdf As New ChilkatPdf
success = pdf.LoadFile("qa_data/pdf/two_page_memo.pdf")
If (success = 0) Then
Debug.Print pdf.LastErrorText
Exit Sub
End If
' The extraction options are passed in a JSON object. An empty JSON object means:
' all pages, automatic reading order, flowing paragraphs, and the default clean-up.
Dim json As New ChilkatJsonObject
' The results are returned in a second JSON object.
Dim jsonOut As New ChilkatJsonObject
' The first argument selects the operation. "text" returns plain text.
' (The other operations are "markdown", "search", "tables" and "assess".)
success = pdf.ExtractText("text",json,jsonOut)
If (success = 0) Then
Debug.Print pdf.LastErrorText
Exit Sub
End If
' The text of all pages is in the "text" member. Each paragraph is one line,
' and pages are separated by a form feed character by default.
Debug.Print jsonOut.StringOf("text")
' Every operation also returns a quality report. A rating of "good" means the text
' can be trusted; "fair" and "poor" mean it should be reviewed, and "none" means the
' PDF has no extractable text (for example, a scanned image that needs OCR).
Debug.Print "Quality: " & jsonOut.StringOf("quality.rating")
' Sample output (the form feed between the pages is shown as \f):
' Riverside Community Garden: Season Summary
'
' The garden opened for its fourth season on the first Saturday in April. All forty-two plots were assigned by the end of the month, and a waiting list of eleven households was kept for the plots that became available over the summer.
'
' Rainfall was close to the ten-year average, so the shared water tanks were refilled only twice. The new drip lines along the north fence worked well and will be extended to the raised beds next spring.
'
' The harvest table donated just over six hundred pounds of produce to the food pantry on Elm Street. Tomatoes, squash and green beans made up most of the weight, with a surprising number of hot peppers in late August.
' \fPlans for Next Season
'
' The committee agreed to replace the tool shed roof before winter and to add a second compost bay. Both projects will be paid for from the plot fees already collected.
'
' Registration for returning gardeners opens on the first of February. New applicants will be taken from the waiting list in the order in which they signed up.
'
' Quality: good