Author Topic: Refering to the last page  (Read 582 times)

0 Members and 1 Guest are viewing this topic.

conrad.drake

  • Newbie
  • *
  • Posts: 34
Refering to the last page
« on: March 23, 2017, 03:11:10 AM »
I want to stamp the last page of a document and can't seem to figure out a syntax for this within the template.  Any clues or do I need to write a script?

This is going to be a command line stamp, to allow me to say "Section X continued in Volume Y" on the last page.  I can get the last page on the command line and could pass it in there through StampRules=%NumberOfPages%. 

Is there a better way than this?

Code: [Select]
for /F tokens^=3^ delims^=^" %i in ('pdfshelltools ExportMetaData "ExportFields=PDFNPages" "%output%") do set last_page=%i
PDFShellTools stamp -s StampRules=%last_page% "DynCustomText='%section%','%next_volume%'" Template=SectionContinued.stp "%output%"

The first line is better understood as follows
Code: [Select]
PDFShellTools ExportMetaData ExportFields=PDFNPages "%output%" > %pages_file%
for /F tokens^=3^ delims^=^" %i in (%pages_file%) do set last_page=%i

RTT

  • Administrator
  • *****
  • Posts: 778
Re: Refering to the last page
« Reply #1 on: March 23, 2017, 08:43:35 PM »
Indeed there is no way to specify a reference to the last page, without explicitly specify its value for each PDF. I've now fixed this by adding a "last" named keyword to the page specifications rules, so in the next release it will be possible to write e.g. 3,5-7,last, or just last in your case, to refer the last page.

Meanwhile your solution is perfectly viable. Or you can use the new dynamic text script functionality to stamp only the last page. You just need to add a text stamp object to the stamp template, set it to dynamic and its text to refer the script name to call using the [<ScriptName>](params) format. The script can be something like this:
Code: [Select]
function StampLastPage(text) {
    return CurrentTask.PageNumber == BatchFile.NumPages ? text : '';
}
The script is created from the dynamic object settings configure dialog.

For a script named "StampLastPage", and having the "section" and "next_volume" values passed from the command line in the "DynCustomText" parameter, as in your example, the dynamic text object text would be:
[<StampLastPage>](Section [C1] continued in Volume [C2]).

And the command line simplified to:
PDFShellTools stamp -s "DynCustomText='%section%','%next_volume%'" Template=SectionContinued.stp "%output%"

Obviously the dynamic text script can be much more complex, and probably even integrate all the logic of your external script and calculate by itself these "section" and "next_volume" values.

conrad.drake

  • Newbie
  • *
  • Posts: 34
Re: Refering to the last page
« Reply #2 on: June 08, 2017, 04:54:29 AM »
Thanks - there's a bunch of options there.