pdftk tips

Number pages

Source: http://cazencott.info/index.php/post/2015/04/30/Numbering-PDF-Pages

Create a PDF that contains only page numbers. In numbers.tex:

\documentclass[12pt,a4paper]{article}
\usepackage{multido}
\usepackage[hmargin=.8cm,vmargin=1.5cm,nohead,nofoot]{geometry}
\begin{document}
\multido{}{31}{\vphantom{x}\newpage}
\end{document}

(where 31 is your total number of pages). Then create numbers.pdf

pdflatex numbers.tex

Finally, stamp your file with page numbers:

pdftk file.pdf multistamp numbers.pdf output single_document_numbered.pdf

Create bookmarks

Instructions for pdftk on Linux. May work on Windows.

Dump the metadata

pdftk input.pdf dump_data > metadata.txt

Write your bookmarks under the line starting with “NumberOfPages”:

BookmarkBegin
BookmarkTitle: My bookmark
BookmarkLevel: 1
BookmarkPageNumber: 34

Then update the metadata of the original file

pdftk input.pdf update_info_utf8 new_metadata.txt output temp.pdf

Finally, in order to avoid losing your zoom level whenever you click a bookmark

sed 's#/Fit#/XYZ#g' temp.pdf > output.pdf

Leave a Reply

Your email address will not be published. Required fields are marked *