Lazarus Pascal Requires Chilkat v11.7.0+
Lazarus Pascal
Rejoin Words Hyphenated at Line Ends
See more PDF Text Extraction Examples
Demonstrates the "dehyphenate" clean-up option (true by default). A word broken at the end of a line ("docu-" / "ment") is rejoined, while a hyphen that belongs to the word ("self-service") is kept. Set the option to false to keep the lines exactly as printed.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 hyphenated.pdf
pdf := TPdf.Create;
success := pdf.LoadFile('qa_data/pdf/hyphenated.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
jsonOut := TJsonObject.Create;
// The paragraph breaks "document", "self-service", "underlying" and "re-issued" at line ends.
// The default rejoins them. "self-service" keeps its hyphen because the word appears with it,
// unbroken, elsewhere on the page; "re-issued" appears nowhere else, so it becomes "reissued".
success := pdf.ExtractText('text',json,jsonOut);
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
WriteLn('---- default (dehyphenate: true) ----');
WriteLn(jsonOut.StringOf('text'));
json.UpdateBool('dehyphenate',False);
success := pdf.ExtractText('text',json,jsonOut);
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
WriteLn('---- dehyphenate: false ----');
WriteLn(jsonOut.StringOf('text'));
// Sample output:
// ---- default (dehyphenate: true) ----
// Self-Service Kiosk Notes
//
// The new self-service kiosk in the lobby prints a visitor badge from the document number on the reservation. Staff should direct first-time visitors to the self-service kiosk rather than the desk, and should keep the paper tray topped up. The underlying software restarts itself overnight; a badge that fails to print is reissued at the desk on request.
// ---- dehyphenate: false ----
// Self-Service Kiosk Notes
//
// The new self-service kiosk in the lobby prints a visitor badge from the docu- ment number on the reservation. Staff should direct first-time visitors to the self- service kiosk rather than the desk, and should keep the paper tray topped up. The under- lying software restarts itself overnight; a badge that fails to print is re- issued at the desk on request.
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.