Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PDF page custom number labels with GhostScript

I want to extract pages from a PDF file which has custom page numbering, e.g. there are pages with the number C1, C2, C3, and after that, 1,2,3,4 etc. starts.

When I use

$ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
   -dFirstPage=22 -dLastPage=36 \
   -sOutputFile=outfile_p22-p36.pdf 100p-inputfile.pdf

FirstPage and LastPage are the page index, starting to count at the first page - which is not what I want

How can I tell GhostView to use the "real" page numbers?

like image 412
zonksoft Avatar asked Oct 04 '22 21:10

zonksoft


1 Answers

You can, given a lot of knowledge about the internals of Ghostscript's PDF interpreter, access the page numbers. It will require a lot of looking around in the Resource/Init/pdf*.ps files (mostly just pdf_main.ps) and an understanding of PostScript, but it is possible. Just not for the faint of heart.

To see an example PS program which digs around inside a PDF to glean information, have a look at toolbin/pdf_info.ps.

If someone comes up with a patch to allow FirstPage/LastPage to take names as labels, then we will consider it. A part of this patch should be a change add an option to pdf_info.ps to print the labels and the real page numbers.

like image 153
Ray Johnston Avatar answered Oct 07 '22 10:10

Ray Johnston