Lazarus Pascal Requires Chilkat v11.7.0+
Lazarus Pascal
Put a Letterhead Behind the First Page of a PDF
See more PDF Watermark Examples
Demonstrates the pdfPage type, which places a page of another PDF as the watermark. It is the way to use a letterhead, a cover overlay or a vector logo that was saved as a PDF, and unlike an image it stays sharp at any size because it is drawn, not resampled. "zOrder" set to back puts it behind the existing content, where a letterhead belongs, and "pages" set to first restricts it to page one.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 two_page_memo.pdf
// The PDF used in this example is available at letterhead.pdf
pdf := TPdf.Create;
success := pdf.LoadFile('qa_data/pdf/two_page_memo.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
json.UpdateString('type','pdfPage');
json.UpdateString('pdf.path','qa_data/pdf/letterhead.pdf');
// The page of the source PDF to use (1 by default). "match" instead of a number places source
// page n on target page n, which suits a set of per-page backgrounds.
json.UpdateInt('pdf.page',1);
// Behind the memo's own text, on page one, scaled to the page.
json.UpdateString('zOrder','back');
json.UpdateString('pages','first');
json.UpdateString('scale.fit','page');
json.UpdateString('id','letterhead');
jsonOut := TJsonObject.Create;
success := pdf.Watermark('add',json,jsonOut);
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
WriteLn('id: ' + jsonOut.StringOf('id') + ' pages: ' + jsonOut.StringOf('pages'));
success := pdf.WriteFile('qa_output/memo_letterhead.pdf');
if (success = False) then
begin
WriteLn(pdf.LastErrorText);
Exit;
end;
// Sample output:
// id: letterhead pages: 1
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.