Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark