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

Clipped, Off-Page and White-on-White Text in PDF Extraction

See more PDF Text Extraction Examples

Demonstrates the "clippedText", "offPageText" and "obscuredText" filters. Text that a reader never sees - hidden by a clipping path, outside the crop box, or drawn in the same color as the box beneath it - is excluded by default, and the quality report notes what was skipped. Each kind can be included.

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 hidden_text.pdf

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

$oJson = ObjCreate("Chilkat.JsonObject")
$oJsonOut = ObjCreate("Chilkat.JsonObject")

;  The page has a visible paragraph plus three hidden lines: one drawn outside its clipping
;  rectangle, one below the crop box, and one in white on a white box.
$bSuccess = $oPdf.ExtractText("text",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("---- default ----" & @CRLF)
ConsoleWrite($oJsonOut.StringOf("text") & @CRLF)

;  The quality report says what was left out.
Local $i = 0
Local $iCount_i = $oJsonOut.SizeOfArray("quality.pages[0].issues")
While $i < $iCount_i
    $oJsonOut.I = $i
    ConsoleWrite("issue: " & $oJsonOut.StringOf("quality.pages[0].issues[i].code") & @CRLF)
    $i = $i + 1
Wend

;  Include everything.
$oJson.UpdateString("clippedText","include")
$oJson.UpdateString("offPageText","include")
$oJson.UpdateString("obscuredText","include")
$bSuccess = $oPdf.ExtractText("text",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("---- clippedText, offPageText, obscuredText: include ----" & @CRLF)
ConsoleWrite($oJsonOut.StringOf("text") & @CRLF)

;  Sample output:

;  ---- default ----
;  Visible Text
;  
;  This paragraph is visible. The page also carries three kinds of text a reader never sees.
;  
;  End of the visible text.
;  issue: obscuredTextSkipped
;  issue: clippedTextSkipped
;  ---- clippedText, offPageText, obscuredText: include ----
;  Visible Text
;  
;  This paragraph is visible. The page also carries three kinds of text a reader never sees.
;  
;  CLIPPED: this line is drawn outside its clipping rectangle.
;  
;  OBSCURED: this line is white on a white box.
;  
;  End of the visible text.
;  
;  OFFPAGE: this line sits below the crop box.