# Modifying PDF files

I need to do some basic editing on existing PDF file. I.e. I need to:

• Add chapters/bookmarks
• Change some page numbering

However I cannot find any tool - GUI or commandline - which would offer this functionality. Is there any alternative to just write such tool myself?

PS. I look only for free tools. Preferably open.

-

## 5 Answers

I use pdftk mainly. But here are some others to consider:

pdfsam (PDF Split and Merge): "pdfsam is an open source tool (GPL license) designed to handle pdf files"

PDFJam "A small collection of shell scripts which provide a simple interface to much of the functionality of the excellent pdfpages PDF file package (by Andreas Matthias) for pdfLaTeX." (You can also use pdfLaTeX directly.)

jPDFTweak: "jPDF Tweak is a Java Swing application that can combine, split, rotate, reorder, watermark, encrypt, sign, and otherwise tweak PDF files."

Inkscape: is a vector graphics editor that can both import PDF pages into its native SVG format, and also export as PDF.

Calibre: Open source ebook management software that can convert PDFs to other formats, and manipulate them in other ways. Comes with command line tools such as pdfmanipulate which can be useful.

Ghostscript of course can do a lot of things with PDF files too.

-
I use pdfjam but it seems none will do the 2 things I explicitly listed. –  Maciej Piechotka Oct 21 '10 at 19:56
I misunderstood the question. Edit the question to make it clear what you meant by "chapters". I assumed you just wanted to insert one part of a PDF inside another. But perhaps you mean the pdf bookmarks (i.e., which appear in the side pane for some viewers)? PDFJam might not, but the pdfpages package for PDFLaTeX, along with the LaTeX hyperref package, can handle those. pdfedit should be able to change page numbers. With pdfLaTeX/pdfpages you could clip the bottom of the page and add new ones. BRISS can crop off headers/footers too, but you'd have to add them back with something else. –  frabjous Oct 21 '10 at 20:18
Oh, and mbPDFasm can apparently also do stuff with bookmarks, but I've never used it: thierry.schmit.free.fr/spip/spip.php?article15&lang=en –  frabjous Oct 21 '10 at 20:24
Another: jPDFBookmarks: flavianopetrocchi.blogspot.com/2009/03/… –  frabjous Oct 21 '10 at 20:27
+1 for jPDFBookmarks –  Maciej Piechotka Oct 21 '10 at 21:50

I know two programs for manipulating PDFs under Linux:

PDEedit "Pdf Editor is primary created for simple editation and manipulation with objects of documents in PDF format and storing them as new version of document. Editation and manipulation with objets is by graphical and by commandline interface too. For simple use command line is using script language, which is usefull in graphical interface too."

and pdftk "If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents."

-
pdfedit: I don't have qt3 and I cannot install it (not in portage) & I cannot get it to compile with qt4 (even with qt3support). –  Maciej Piechotka Oct 21 '10 at 19:36

The only way I found to add page numbers to a PDF was with LaTeX:

Create a file /usr/local/bin/add-page-numbers.tex

\documentclass[8pt]{article}
\usepackage[final]{pdfpages}
\usepackage{fancyhdr}

\topmargin 70pt
\oddsidemargin 150pt

\pagestyle{fancy}
\rfoot{\Large\thepage}
\cfoot{}
\renewcommand {\headrulewidth}{0pt}
\renewcommand {\footrulewidth}{0pt}

\begin{document}
\includepdfset{pagecommand=\thispagestyle{fancy}}
\includepdf[pages=-]{input.pdf}
\end{document}


And a file /usr/local/bin/pdf-numbers

#!/bin/bash
name="${1%\.pdf}-numbers" wd="$(pwd)"
dir=/tmp/pdf-numbers
mkdir -p "$dir" cp "$1" "$dir/input.pdf" cd "$dir"
pdflatex --jobname "$name" /usr/local/bin/add-page-numbers.tex > /dev/null mv "$name.pdf" "$wd" rm -r "$dir"


Make the latter file executable, and run it with

    pdf-numbers example.pdf


It will create a pdf file called example-numbers.pdf (and overwrite it if it already exists!).

-
Working very well. Imperfection lies in absolute paths, but that's nothing I couldn't manage. However, could you elaborate how did u added these numbers and how change positions of numbers? –  Miro Jan 16 at 9:48

pdfimport for openoffice is a good alternative to edit PDF documents and re-export to PDF or save to another format. The imported PDF can be edited with OpenOffice Draw.

-

latex with the pdfpages packages can do most of these things.

Specifically on how to add bookmarks, see http://michaelgoerz.net/blog/2011/04/pdf-bookmarks-with-latex/

-
Welcome to Stack Overflow. Please don't just link to external content, include the most relevant parts directly in your answer as well. (An answer containing only a link to your blog might well be considered spam.) –  Gilles May 3 '11 at 21:44