i want to add page numbers to each pdf page...if a pdf page has 2 images and user want 3 copies then it must need to be print as
like this .... but my output always printing copy 1 of 3 in the all pages... but the console output will give me the correct text and pdf output give the wrong text .Here is my code.
function printService.PrintImageFromStream(fin: TStream;reqid, rtype: string; ncopies, npages: Integer): Integer;
var
DPL: TDebenuPDFLibrary1114;
i,c,imgID,imgsID, unlockResult, iPrintOptions, res: Integer;
cPrinter: WideString;
err, pageText: string;
begin
Result := 0;
try
DPL := TDebenuPDFLibrary1114.Create;
with DPL do
try
unlockResult := unlockKey('0000');
if unlockResult = 1 then
begin
cPrinter := DPL.NewCustomPrinter(GetPrinterName(rtype));
DPL.SetupCustomPrinter(cPrinter, 4, ncopies);
DPL.SetupCustomPrinter(cPrinter, 7, 2);
for c := 1 to ncopies do
begin
for i := 1 to npages do
begin
fin.Position := 0;
CompressImages(1);
imgID := AddImageFromStream(fin, -i);
if imgID > 0 then
begin
SelectImage(imgID);
SetPageDimensions(ImageWidth, ImageHeight);
SetOrigin(1);
if DrawImage(0, 0, ImageWidth, ImageHeight) <> 1 then
raise Exception.Create('unsupported image');
pageText := Format('Copy %d of %d', [c, ncopies]);
AllocConsole;
Writeln('pageText ', pageText);
DPL.SetTextColor(0, 0, 0);
DPL.SelectFont(AddStandardFont(5));
DPL.SetTextSize(36);
DPL.DrawText(50, 226, pageText);
SelectPage(NewPage);
end
else
raise Exception.Create('unsupported image');
end;
end;
iPrintOptions := DPL.PrintOptions(1, 0,'veloprint[' + reqid + ']');
res := DPL.PrintDocument(cPrinter, 1, npages, iPrintOptions);
if res <> 0 then
begin
Result := 200;
end
else
begin
ShowErrorNotification('Printer error');
raise Exception.Create('[error] [' + reqid + '] ' + 'PrintImageFromStream: Printer error');
end;
end
else
raise Exception.Create('[error] [' + reqid + '] ' + 'DPL licence error');
finally
DPL.Free;
end;
except
On E: Exception do
begin
raise Exception.Create(err);
end;
end;
end;