How to add page numbers to Postscript/PDF

前端 未结 14 1921
臣服心动
臣服心动 2020-12-07 12:06

If you\'ve got a large document (500 pages+) in Postscript and want to add page numbers, does anyone know how to do this?

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 12:08

    I used to add page numbers to my pdf using latex like in the accepted answer.

    Now I found an easier way: Use enscript to create empty pages with a header containing the page number, and then use pdftk with the multistamp option to put the header on your file.

    This bash script expects the pdf file as it's only parameter:

    #!/bin/bash
    input="$1"
    output="${1%.pdf}-header.pdf"
    pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
    enscript -L1 --header='||Page $% of $=' --output - < <(for i in $(seq "$pagenum"); do echo; done) | ps2pdf - | pdftk "$input" multistamp - output $output
    

提交回复
热议问题