Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
pdf: HCkPdf;
json: HCkJsonObject;
jsonOut: HCkJsonObject;
i: Integer;
count_i: Integer;
begin
success := 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
pdf := CkPdf_Create();
success := CkPdf_LoadFile(pdf,'qa_data/pdf/hidden_text.pdf');
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
json := CkJsonObject_Create();
jsonOut := CkJsonObject_Create();
// 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.
success := CkPdf_ExtractText(pdf,'text',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
Memo1.Lines.Add('---- default ----');
Memo1.Lines.Add(CkJsonObject__stringOf(jsonOut,'text'));
// The quality report says what was left out.
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonOut,'quality.pages[0].issues');
while i < count_i do
begin
CkJsonObject_putI(jsonOut,i);
Memo1.Lines.Add('issue: ' + CkJsonObject__stringOf(jsonOut,'quality.pages[0].issues[i].code'));
i := i + 1;
end;
// Include everything.
CkJsonObject_UpdateString(json,'clippedText','include');
CkJsonObject_UpdateString(json,'offPageText','include');
CkJsonObject_UpdateString(json,'obscuredText','include');
success := CkPdf_ExtractText(pdf,'text',json,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
Memo1.Lines.Add('---- clippedText, offPageText, obscuredText: include ----');
Memo1.Lines.Add(CkJsonObject__stringOf(jsonOut,'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.
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(jsonOut);