Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.7.0+

Extract PDF Text to a StringBuilder and Save to a File

See more PDF Text Extraction Examples

Demonstrates ExtractTextSb, which writes the extracted text to a StringBuilder instead of returning it as a JSON string. Use it for large documents. The JSON output still receives the quality report.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  This example requires the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

;  The PDF used in this example is available at long_report.pdf

$oPdf = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf.LoadFile("qa_data/pdf/long_report.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Number of pages: " & $oPdf.NumPages & @CRLF)

;  ExtractTextSb takes the same operation and options as ExtractText, but the text
;  goes to a StringBuilder.  This avoids building a very large JSON string for
;  documents with many pages.
$oJson = ObjCreate("Chilkat.JsonObject")
$oSbText = ObjCreate("Chilkat.StringBuilder")
$oJsonOut = ObjCreate("Chilkat.JsonObject")

$bSuccess = $oPdf.ExtractTextSb("text",$oJson,$oSbText,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Extracted " & $oSbText.Length & " characters." & @CRLF)

;  Save the text to a file.
$bSuccess = $oSbText.WriteFile("qa_output/long_report.txt","utf-8",False)
If ($bSuccess = False) Then
    ConsoleWrite($oSbText.LastErrorText & @CRLF)
    Exit
EndIf

;  The JSON output does not contain the text, but it still has the quality report.
ConsoleWrite("Quality: " & $oJsonOut.StringOf("quality.rating") & @CRLF)
ConsoleWrite("Pages with no text (need OCR): [" & $oJsonOut.StringOf("quality.pagesNeedingOcr") & "]" & @CRLF)

;  Sample output:

;  Number of pages: 3
;  Extracted 4522 characters.
;  Quality: good
;  Pages with no text (need OCR): []