Question

I generate a PDF from a set of PNG files using this command:

convert --  $(ls -v -- src/*.png) out/book.pdf

where there're some files with names like -03.png, which I need to have smaller page numbers than others. But I get a PDF which has -01 having page number 1, -02 number 2, etc., and 01 starts from page number 6.

The PDF is a scanned book, which has some elements like table of contents etc. which aren't included in page numbering. I remember to have seen some PDFs which have special page numbers like vii before normal Arabic numbers start.

I've tried using -scene -5 to add an offset to page numbers, but this didn't change the result.

So what should I instead do to make page "01.png" have page number 1, etc., and previous ones have some other numbers (negative or Latin, anything) and appear at the beginning of the document?

Était-ce utile?

La solution

First, you want to sort files numerically counting optional minus sign, which you won't do with command you show.

Second, you talk about PageLabels for PDF pages, which you can add using Ghostscript and pdfmark operator.

Try this command:

ls src/*.png | \
sort -n | \
convert @- pdf:- | \
gs \
  -sDEVICE=pdfwrite \
  -o out/book.pdf \
  -c '[{Catalog}<</PageLabels<</Nums[0<</P(-3)>>1<</P(-2)>>2<</P(-1)>>3<</S/D>>]>>>>/PUT pdfmark' \
  -f -

It's for 3 pages -3, -2 and -1, followed by any number of pages labelled 1, 2, 3 etc. Modify according to your needs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top