PowerBuilder Requires Chilkat v11.7.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Json
oleobject loo_JsonOut
long i
long li_Count_i
li_Success = 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
loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
destroy loo_Pdf
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/hidden_text.pdf")
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("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.
li_Success = loo_Pdf.ExtractText("text",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "---- default ----"
Write-Debug loo_JsonOut.StringOf("text")
// The quality report says what was left out.
i = 0
li_Count_i = loo_JsonOut.SizeOfArray("quality.pages[0].issues")
do while i < li_Count_i
loo_JsonOut.I = i
Write-Debug "issue: " + loo_JsonOut.StringOf("quality.pages[0].issues[i].code")
i = i + 1
loop
// Include everything.
loo_Json.UpdateString("clippedText","include")
loo_Json.UpdateString("offPageText","include")
loo_Json.UpdateString("obscuredText","include")
li_Success = loo_Pdf.ExtractText("text",loo_Json,loo_JsonOut)
if li_Success = 0 then
Write-Debug loo_Pdf.LastErrorText
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut
return
end if
Write-Debug "---- clippedText, offPageText, obscuredText: include ----"
Write-Debug loo_JsonOut.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.
destroy loo_Pdf
destroy loo_Json
destroy loo_JsonOut