Lazarus Pascal Requires Chilkat v11.7.0+
Lazarus Pascal
Exclude Rotated Margin Text from PDF Extraction
See more PDF Text Extraction Examples
Demonstrates the "rotatedText" filter. Text that is not aligned with the page, such as a vertical "CONFIDENTIAL" label in the margin, is included by default (after the upright text) and flagged in the quality report; "exclude" leaves it out.Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Pdf,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pdf: TPdf;
json: TJsonObject;
jsonOut: TJsonObject;
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 rotated_margin.pdf
pdf := TPdf.Create;
success := pdf.LoadFile('qa_data/pdf/rotated_margin.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
jsonOut := TJsonObject.Create;
// The page has a paragraph and, rotated 90 degrees along the left margin, "CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION".
success := pdf.ExtractText('text',json,jsonOut);
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
WriteLn('---- default (rotated text included) ----');
WriteLn(jsonOut.StringOf('text'));
WriteLn('issue: ' + jsonOut.StringOf('quality.pages[0].issues[0].code'));
json.UpdateString('rotatedText','exclude');
success := pdf.ExtractText('text',json,jsonOut);
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
WriteLn('---- rotatedText: exclude ----');
WriteLn(jsonOut.StringOf('text'));
// Sample output:
// ---- default (rotated text included) ----
// Restoration Budget Summary
//
// Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
//
// CONFIDENTIAL - DRAFT - NOT FOR DISTRIBUTION
// issue: rotatedText
// ---- rotatedText: exclude ----
// Restoration Budget Summary
//
// Spending for the season came in slightly under the approved budget, largely because the parapet work took less time than expected. The lens loan carries no fee, but the society is responsible for insurance and for the specialist cleaning.
pdf.Free;
json.Free;
jsonOut.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.