# Text annotations and image additions to PDF file using free software

I'm mostly interested in annotating a PDF file with text at a predetermined position. GUIs and command line utilities are both Ok, but only free software solutions, please. However, I included image additions for completeness.

To be clear, the annotations must be part of the PDF file, otherwise it is not useful.

There are two similar questions on Ask Ubuntu, but they are both a couple of years old. These are How can I add text and images (for example, a signature) to a PDF? and How can I edit a picture into an existing PDF file?

I've tried Xournal, which does work. However, I think a little tutorial about how to do this would be good, so you want to add a small tutorial on how to use Xournal to accomplish these tasks, please add an answer.

I also tried updf, which didn't work for me, though this answer and this one for example says it can. I rebuilt the package (which is pure Python) on Debian Wheezy, using the sources from the updf PPA. It seems quite primitive and the "Save As" dialog did not even have a save button. If other people have had different experiences, please post.

For each answer, please provide a brief tutorial with screenshots if appropriate, as to how you accomplished this task.

• What was wrong with libreoffice? – goldilocks Jan 18 '14 at 15:29
• @goldilocks I've not used it. If it works for you, write an answer. – Faheem Mitha Jan 18 '14 at 15:36
• Libreoffice 3.5.4 tries to open a PDF file as text here. Maybe I'm doing something wrong. – Faheem Mitha Jan 18 '14 at 16:28
• I successfully edited a PDF to add colours to different states in a b/w state diagram in some document at work using libreoffice and I was severely impressed by the result (it was almost impossible to notice any difference other that the line thickness was slightly different a few places). – hlovdal Jan 18 '14 at 18:19
• @hlovdal Can you give some details on how you did that? – Faheem Mitha Jan 18 '14 at 18:35

PDF files appear to open in LibreOffice Draw. I did nothing special other than open the file like so:

$libreoffice carcut_01.pdf Once in LibreOffice Draw I simply annotated the PDF as if it were a normal document/image. Once done I clicked the PDF icon in Draw's toolbar to export the file out as a new PDF file. This was the result of my effort. ### But LibreOffice doesn't work for me? If you're encountering an issue with Draw not being able to do this (I was using version of LibreOffice): • Version: 4.1.4.2 • Build ID: 4.1.4.2-4.fc19 **NOTE:* You might be missing this package which is part of LibreOffice:$ rpm -aq|grep "libre.*pdf"
libreoffice-pdfimport-4.1.4.2-4.fc19.x86_64

This is what the package looks like on Red Hat based distros such as Fedora. I would assume that on Debian/Ubuntu there is a similarly named package, probably libreoffice-pdfimport.

### Alternatives?

You could try Okular.

Okular allows you to review and annotate your documents. Annotations created in Okular are automatically saved in the internal local data folder for each user. Okular does not implicitly change any document it opens.

### What else?

As @Terdon's answer shows, you can also use GIMP, along with a whole host of other tools. @Terdon also was kind enough to post this link in our chatroom which has a list of other tools for annotating PDFs as well as viewing them.

• Notes specific to Debian: I'm on Wheezy but used the libreoffice backport, currently 1:4.1.4-2. I installed libreoffice, but had to add libreoffice-pdfimport, as this is not pulled in by libreoffice. Without that it doesn't work. Click on the T on the bottom bar to insert text. Attempting to overwrite the existing PDF fails here. Additionally, the resulting output looks quite poor compared to the original - a PDF generated from LaTeX output. This may (and probably does) work with the wheezy Libreoffice. I haven't bothered to check. – Faheem Mitha Jan 30 '14 at 16:35
• I tried the Okular edit option. This is the Review option under Tools. However, it does not show up with any PDF viewer, and therefore is clearly not part of the PDF, so that makes it useless. – Faheem Mitha Sep 20 '15 at 19:32
• I was able to open a PDF in LibreOffice Draw, draw a rectangle and export back to PDF. However, the PDF (originally produced from Docbook) had a clickable table of contents - the layout of this was sligtly messed up and the items can no longer be clicked to jump. – Oskar Berggren May 11 '16 at 22:55

Since you just want to overlay text at a predetermined position, you can use pdftk to do this.

You need two PDF files. One is the PDF file that you want to stamp with the text. The other PDF file is the text you want to stamp. The second one must have a transparent background. You can easily make this with, say, LibreOffice Draw, and print to pdf using cups-pdf. Exporting to PDF—even if you don't select PDF1/A—will make an opaque background.

Then you do:

pdftk input.pdf stamp overlay.pdf output stamped.pdf

If you want different overlays on different pages, create a multi-page overlay.pdf (overlay page 1 goes on input page 1, overlay page 2 on input page 2, etc.) and then:

pdftk input.pdf multistamp overlay.pdf output stamped.pdf

Since screenshots are popular, here is what the input and results look like. The input.pdf was of course made using LibreOffice's all-important smiley tool:

## How make a PDF with CUPS-PDF

CUPS-PDF is a print driver for CUPS that creates PDF files from print jobs. To use it, you must be using CUPS. Install the cups-pdf package (required at least in Debian). Visit the CUPS administrative interface at http://localhost:631/admin and click 'Add Printer'. You should see "CUPS-PDF (Virtual PDF Printer)" as an option. Select it, press continue. Fill in the queue names, etc and continue again. If asked for a PPD, it's under generic.

Once you've added that printer, it can be fully configured in /etc/cups/cups-pdf.conf.

To use it, print like normal, but select it as the printer, instead of your normal printer. The PDF file will be plopped into $HOME/PDF by default. • CUPS might prompt for authentication while adding a printer, the user needs ti be added to the required group (sys by default) – aksh1618 Jan 6 at 10:41 Okular can make annotations on PDFs, as of the version in Debian 8 (Jessie). This is the version: okular --version Qt: 4.8.6 KDE Development Platform: 4.14.2 Okular: 0.20.2 Here is how it works: For details, see the Annotation reference page from the Okular manual. To quote that page: Since Okular 0.15 you can also save annotations directly into PDF files. This feature is only available if Okular has been built with version 0.20 or later of Poppler rendering library. First, you need to annotate the PDF. You can do this via the menu or via a keystroke. You can find the tools under Tools->Review, or via the keystroke F6. This will bring up a menu on the left, with a variety of options. Probably the best option for inline annotations is "Inline Note". Follow instructions in the link to save the note. As noted in the link, the background color, font and other features of the note can be customized. See also Change and save pdf annotation setting in Okular?. By default, the annotation information is stored in in xml files located in ~/.kde/share/apps/okular/docdata or more generally, in the location$(kde4-config --localprefix)/share/apps/okular/docdata/

To save the annotation to the PDF file, as is desirable, you need to save the annotations back to the file using Save As.

The annotation is seen by xpdf and evince (which throws the warning " WARNING **: Unimplemented annotation: POPPLER_ANNOT_FREE_TEXT. It is a known issue and it might be implemented in the future." but still shows the annotation), but not by acroread (9.5.5) or the PDF plugin of Chromium (45.0.2454.85). It also prints Ok using gtklp, a CUPS frontend.

A few more tips:

• The Review feature can be added to the toolbar: Settings - Configure toolbars - change under Toolbar: Main Toolbar okular_part - filter available actions by searching "Review", and add it to the current actions to the right.

• The annotations options can be edited, new variants can be added: right click on the Review buttons and select "Configure Annotations"

You can also use gimp:

\$ gimp foo.pdf

Click on "Import":

Play with it:

Save it:

!

• …but you lose all vector information. – wchargin Oct 15 '15 at 0:56

A good choice for annotation is TeX, specifically LaTeX in conjunction with the LaTeX package pdfpages, and the drawing package TikZ.

An example script follows. This is the overlay of the two page document text.pdf. The command \includepdf from the pdfpages package is invoked with the pagecommand option to include the first page of the pdf, along with some overlaid text using TikZ. Then the second page is included using \includepdf, but without any annotations.

This is an extremely powerful, yet simple method, because it uses the full power of TeX and TikZ.

If you are not familiar with TeX/LaTeX, you can test this by copying this script, calling it (say) example.tex, changing text.pdf to any 2 page PDF you have. Then just run

pdflatex example.tex

making sure that example.tex and text.pdf are at the same directory level.

If you want to generate a 2 page pdf for testing, a simple way of doing is to invoke groff.

echo .bp | groff -T pdf > text.pdf

.bp stands for break page, and creates a two page blank PDF. This command is courtesy of James Lowden.

\documentclass[a4paper]{article}
\usepackage{pdfpages}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\begin{document}

\includepdf[pagecommand=
{\begin{tikzpicture}[remember picture, overlay]