Delphi 10.1, View v. 4. I'm trying to use the STAMPTEXT to add a footer to each page in a PDF I generate out of several files. The left part of the footer is intended to be the filename, the right a page number.
Have two ideas: Merging using a string list containing all files, and one appending a file at a time. But I have great problems understanding the Options-part. BTW. what does @ClearText mean? It is mentioned several times but never explained.
This is what I try:
To start with, I built a string list containing the files to be generated, but then I can't add a footer for each new file. The above works somewhat crappy, as the [##] results in all text is printed on top of each other on page 1, one less on the next page, ending with a correct page at the last page.
Adding the filename has the same issue.
- result := false; ExpCount := 0;{$IFNDEF EMBEDDED} WPViewPDFLoadDLL('wPDFViewPlus04.dll');{$ENDIF} List := TStringList.Create; try List.QuoteChar := '"'; for PDFDoc in self do begin if PDFDoc.IsSupported then begin if PDFDoc.IsGenerated then if not PDFDoc.Generate then raise Exception.CreateFmt('PDFDoc: %s did not generate',[PDFDoc.OutputFilename]); with PDFDoc do if PDFDoc.Generated <> 0.0 then List.Add(OutputPath + OutputFilename); end; end; if List.Count > 0 then begin Stamps := TStringList.Create; try Stamps.LineBreak := '\r\n'; Stamps.Add(format('72,32=%s',[fFilename])); Stamps.Add('@Page numbering part 2 - arabic'); Stamps.Add('NUMFORMAT=1'); Stamps.Add('@cleartext'); Stamps.Add('ORIGIN=2'); Stamps.Add('-40,-25=[#]/[##]'); Options := '"DEBUG=0","DELETESOURCE=1","LOGFILE='+fPath + 'pdfmerge.log","STAMPTEXT='+Stamps.Text+ '"'; finally Stamps.Free; end; ExpCount := wpview_pdfMergeW(PWideChar(List.CommaText) ,PWideChar(fPath + fFilename) ,PWideChar('test') ,PWideChar(WPViewPDF_LicName) ,PWideChar(WPViewPDF_LicKey) ,WPViewPDF_LicCode ,PWideChar(options)); result := ExpCount > 0; end; finally List.Free; end;
Then I tried this: Add each file individually
- List.QuoteChar := '"';
- for PDFDoc in self do
- if PDFDoc.IsGenerated then
- begin
- List.Clear;
- if FileExists(fPath + fFilename) then
- List.Add(fPath + fFilename);
- List.Add(PDFDoc.OutputPath + PDFDoc.OutputFilename);
- Stamps := TStringList.Create;
- try
- Stamps.Clear;
- Stamps.LineBreak := '\r\n';
- Stamps.Add('PAGENO=ALL');
- Stamps.Add('@clearText');
- Stamps.Add('NUMFORMAT=1');
- Stamps.Add('ORIGIN=2');
- Stamps.Add('-40,-25=[#]/[##]');
- Stamps.Add('ORIGIN=3');
- Stamps.Add(format('40,-25=%s',[PDFDoc.OutputFilename]));
- Options := '"DEBUG=0","DELETESOURCE=1","LOGFILE='+fPath + 'pdfmerge.log","STAMPTEXT='+Stamps.Text+ '"';
- finally
- Stamps.Free;
- end;
- ExpCount := wpview_pdfMergeW(PWideChar(List.CommaText)
- ,PWideChar(fPath + fFilename)
- ,PWideChar('test')
- ,PWideChar(WPViewPDF_LicName)
- ,PWideChar(WPViewPDF_LicKey)
- ,WPViewPDF_LicCode
- ,PWideChar(options));
- end;
This didn't work either, and It also is so clumsy that it must be the wrong approach. How do I do this the right way?
A second issue is that when the PDF is generated, the PDF always triggers a "save form" in the Acrobat Reader. Adding a password (shown above) didn't help. Any ideas to rid this message?
A final question to something I may have overlooked in the manuals, is how to link the DLL(s?) to the exe-file. Is there a recipe (that works)?
Thanks in advance.
Henrik