I nailed it! Created this function:
Code
function TPDFDoc.GetInformation: integer;const MAXPAGES = 3000; PAGESTRUCTSIZE = MAXPAGES shl 1 + MAXPAGES;var i: integer; Pages: array of integer;begin if not assigned(wpview_pdfGetInfoW2) then raise Exception.Create('Function pdfGetInfoW2 is not available'); SetLength(Pages, PAGESTRUCTSIZE); result := wpview_pdfGetInfoW2(PWideChar(fOutputPath + fOutputFilename) , @Pages[0] , PAGESTRUCTSIZE , '' // Password , PWideChar(WPViewPDF_LicName) , PWideChar(WPViewPDF_LicKey) , WPViewPDF_LicCode , 5); if result < 0 then raise Exception.CreateFmt('Cannot open file: %s',[fOutputFilename]); if result > MAXPAGES then raise Exception.CreateFmt('Cannot fully scan file: %s',[fOutputFilename]);end;
And when compiling the PDF, I do this (note that the fStampText.LineBreak is set to '\r\n' when created):
Code
function TPDFDocList.Generate: boolean;
var
Options: string;
List: TStringList;
PDFDoc: TPDFDoc;
i, DocumentCount, SubPageCount, PageCount: integer;
begin
result := false;
DocumentCount := 0;
{$IFNDEF EMBEDDED}
WPViewPDFLoadDLL('wPDFViewPlus04.dll');
{$ENDIF}
List := TStringList.Create;
try
fStampText.Clear;
PageCount := 0;
List.QuoteChar := '"';
for PDFDoc in self do
begin
if PDFDoc.IsSupported then
begin
if not PDFDoc.IsGenerated then
if not PDFDoc.Generate then
raise Exception.CreateFmt('PDFDoc: %s did not generate',[PDFDoc.OutputFilename]);
with PDFDoc do
if PDFDoc.IsGenerated then
begin
SubPageCount := PDFDoc.GetInformation;
for i := 0 to SubPageCount - 1 do
begin
fStampText.Add(format('PAGENO=%d',[PageCount + i + 1]));
fStampText.Add('@CLEARTEXT');
fStampText.Add('ORIGIN=2');
fStampText.Add('-40,-25=[#]/[##]');
fStampText.Add('ORIGIN=3');
fStampText.Add(format('40,-25=%s',[PDFDoc.OutputFilename]));
end;
Inc(PageCount,SubPageCount);
List.Add(OutputPath + OutputFilename);
end;
end;
end;
if List.Count > 0 then
begin
assert(fStampText.Count > 0,'StampText is empty');
Options := format('"DEBUG=0","DELETESOURCE=1","LOGFILE=%s","STAMPTEXT=%s"',[fPath + 'pdfmerge.log',fStampText.Text]);
DocumentCount := wpview_pdfMergeW(PWideChar(List.CommaText)
,PWideChar(fPath + fFilename)
,PWideChar('')
,PWideChar(WPViewPDF_LicName)
,PWideChar(WPViewPDF_LicKey)
,WPViewPDF_LicCode
,PWideChar(options));
result := DocumentCount > 0;
end;
finally
List.Free;
end;
end;
Alles anzeigen
This produces the result I wanted. Thanks for the sparring. Please comment if my solution can be optimized.