This is a simple example for Stamp Metafile. Metafiles should always be EMF, not WMF.
StampMeta:=TmetaFile.create;
StampMetaCan := TMetafileCanvas.Create(StampMeta,0);
try
StampMetaCan.Font.Height := 18;
StampMetaCan.Font.Color := clRed;
StampMetaCan.Font.Name := 'Tahoma';
StampMetaCan.Brush.Style := bsClear;
y:= Round(2 / 2.54 * Screen.PixelsPerInch);
x:= Round(2 / 2.54 * Screen.PixelsPerInch);
lst:=TStringlist.create;
lst.text:=strpas('This is a test text (2,2cm) ');
idx:=0;
for n := lst.count - 1 downto 0 do
begin
StampMetaCan.TextOut(x,y-((StampMetaCan.Font.Height*2)*(n+1)), lst[idx]);
inc(idx);
end;
lst.free;
nrP:=wp.CommandEx(COMPDF_GetPageCount,0);
finally
StampMetaCan.Free;
end;
wp.CommandStrEx(495,inttostr(nrP-1)+'-'+inttostr(nrP), StampMeta.Handle);
wp.Plus.SaveToFile(pchar('newfile.pdf'));
StampMeta.free;
Alles anzeigen
This is the sample code to convert a PDF file into a watermark
The command COMPDF_LoadFileAsWatermark is used to load a PDF file and convert a certain page into a watermark. The ID of the new watermark is retuned. If the PDF file was already loaded, it will be reused. So it is possible to subsequently use different pages from the same PDF file.
The command COMPDF_ApplyWatermark is used to apply the watermark with the given id to certain pdf pages. The string parameter of this command is used to select the destination pages. It is possible to select "all", "odd" or "even" pages. Alternatively a range can be specified, such as "1-3,5,7,9-1000".
To add a positioning mode add it after ";". Positioning modes are 0=over page, 256=under page (default)
Instead of page list also the text odd and even is allowed. Returns the number of modified pages
i := WPViewPDF1.CommandStrEx( COMPDF_LoadFileAsWatermark,
OpenDialog1.FileName, StrToInt(edSourcePage.Text)-1);
if i<=0 then
ShowMessage('The PDF file cannot be loaded as watermark - Code=' + IntToStr(i))
else
begin
if rbOddPages.Checked then
i := WPViewPDF1.CommandStrEx( COMPDF_ApplyWatermark, 'odd', i)
else if rbEvenPages.Checked then
i := WPViewPDF1.CommandStrEx( COMPDF_ApplyWatermark, 'even', i)
else i := WPViewPDF1.CommandStrEx( COMPDF_ApplyWatermark, edPageRange.Text, i);
if i<=0 then
ShowMessage('The PDF page cannot be applied as watermark');
end;
Alles anzeigen