Xbase++ Requires Chilkat v11.7.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oPdf
LOCAL oJson
LOCAL oJsonOut
LOCAL i
LOCAL nCount_i
nSuccess := 0
// 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 := CreateObject("Chilkat.Pdf")
nSuccess := oPdf:LoadFile("qa_data/pdf/hidden_text.pdf")
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJsonOut := CreateObject("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.
nSuccess := oPdf:ExtractText("text", oJson, oJsonOut)
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()
RETURN
ENDIF
? "---- default ----"
? oJsonOut:StringOf("text")
// The quality report says what was left out.
i := 0
nCount_i := oJsonOut:SizeOfArray("quality.pages[0].issues")
DO WHILE i < nCount_i
oJsonOut:I := i
? "issue: " + oJsonOut:StringOf("quality.pages[0].issues[i].code")
i := i + 1
ENDDO
// Include everything.
oJson:UpdateString("clippedText", "include")
oJson:UpdateString("offPageText", "include")
oJson:UpdateString("obscuredText", "include")
nSuccess := oPdf:ExtractText("text", oJson, oJsonOut)
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()
RETURN
ENDIF
? "---- clippedText, offPageText, obscuredText: include ----"
? oJsonOut:StringOf("text")
// 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.
oPdf:destroy()
oJson:destroy()
oJsonOut:destroy()