3

Q: how can I change PDF page labels with pdf-tools?

pdf-tools has the capacity to annotate PDFs, which is great. Can it also change the page labels as well? That is, not the raw page number, but the labeled page number?

Use Case

I scan a lot of books and articles. I would like to be able to jump to the page numbers as enumerated in the books/articles, not just the nominal page number of the PDF.

Example: if I scan an article that ranges from pages 11-20, I want to be able to embed the pages 11-20 so that I can tell pdf-tools to jump to, say, page label 12, rather than have to use the nominal page numbers (in this case, PDF page 2 which would correspond to page label 12).

What I Found

A quick apropos search turns up pdf-info-pagelabels, pdf-view-current-pagelabel, and pdf-view-goto-label. None of these appear to allow me to edit the page labels.

Alternatives Welcome

In the event that pdf-tools does not have this capability, I'd be glad to know of (linux) command line tools that allow me to edit page labels, as I'm sure I could rig up something with the right tool.

1
  • 1
    the pdftk program provides options for dumping metadata, i.e. pdftk input.pdf dump_data, and adding new metadata, pdftk in.pdf update_info in.info output out.pdf, so that might be a way to accomplish this. I don't see anything in pdf-tools or the poppler library that it uses that supports this
    – Tyler
    Commented May 7, 2020 at 14:31

1 Answer 1

3

You can do this with the Java variant of pdftk, starting from version 3.1.0.

First, create a file with the metadata you want, e.g.:

PageLabelBegin
PageLabelNewIndex: 1
PageLabelStart: 1
PageLabelPrefix: Cover
PageLabelNumStyle: NoNumber
PageLabelBegin
PageLabelNewIndex: 2
PageLabelStart: 1
PageLabelPrefix: Back Cover
PageLabelNumStyle: NoNumber
PageLabelBegin
PageLabelNewIndex: 3
PageLabelStart: 1
PageLabelNumStyle: LowercaseRomanNumerals
PageLabelBegin
PageLabelNewIndex: 27
PageLabelStart: 1
PageLabelNumStyle: DecimalArabicNumerals

Then apply it to the PDF file:

pdftk book.pdf update_info metadata.txt output book-with-metadata.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.