Text annotations and image additions to PDF file using free software

30,763

Solution 1

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.

enter image description here

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.

enter image description here

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

enter image description here

Solution 2

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.

    ss of draw

This was the result of my effort.

    ss of xpdf

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.

screenshot

   ss of okular

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.

Solution 3

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:

Screenshot


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.

Solution 4

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]
    \node at (2,2.0){\large{\textbf{PLEASE WRITE EMAIL ADDRESS:}}};
    \draw[thick,latex-] (current page footer area.south east) -- +(-3.4cm,-2.2cm)
    node[pos=1,anchor=east] (a) {\large\textbf{{CONTINUED ON NEXT PAGE}}};
  \end{tikzpicture}}
,pages=1]{text.pdf}
\includepdf[pages=2]{text.pdf}

\end{document}

It's useful to lay a coordinate grid over the page when doing this, so positioning becomes easier. See, for example, the recipes given in the answers to Grid with coordinates on all sides? and the original answer by Loop Space linked in the question.

Here is an image of the result:

Example page

Solution 5

You can also use gimp:

$ gimp foo.pdf

                                                      enter image description here

Click on "Import":

                                          enter image description here

Play with it:

                                           enter image description here

Save it:

   !enter image description here

Share:
30,763

Related videos on Youtube

Alen Milakovic
Author by

Alen Milakovic

Updated on September 18, 2022

Comments

  • Alen Milakovic
    Alen Milakovic almost 2 years

    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.

    • goldilocks
      goldilocks over 10 years
      What was wrong with libreoffice?
    • Alen Milakovic
      Alen Milakovic over 10 years
      @goldilocks I've not used it. If it works for you, write an answer.
    • Alen Milakovic
      Alen Milakovic over 10 years
      Libreoffice 3.5.4 tries to open a PDF file as text here. Maybe I'm doing something wrong.
    • hlovdal
      hlovdal over 10 years
      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).
    • Alen Milakovic
      Alen Milakovic over 10 years
      @hlovdal Can you give some details on how you did that?
    • hlovdal
      hlovdal over 10 years
      Actually it was just like editing a normal document - mark the text and then select the wanted colour from the toolbar. Before starting I was expecting to have to add some kind of overlay to do what I wanted, but it turned out to be dead simple. I am not sure about the exact version I used, but it is a couple of months ago and I am runnig Fedora 19.
    • Alen Milakovic
      Alen Milakovic over 10 years
      @hlovdal Ok, how did you import the document? When I do libreoffice foo.pdf I get what looks like a text file which lots of funny characters. In your case, does what you get look like the PDF file? If you could give the openoffice version that would be useful.
    • hlovdal
      hlovdal over 10 years
      I do not remember exactly, I can check when I get to the office.
    • Alen Milakovic
      Alen Milakovic over 10 years
      @hlovdal did you get a chance to take a look at this issue?
    • becko
      becko almost 7 years
  • Alen Milakovic
    Alen Milakovic over 10 years
    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.
  • Alen Milakovic
    Alen Milakovic almost 9 years
    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.
  • wchargin
    wchargin over 8 years
    …but you lose all vector information.
  • Oskar Berggren
    Oskar Berggren about 8 years
    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.
  • aksh1618
    aksh1618 over 5 years
    CUPS might prompt for authentication while adding a printer, the user needs ti be added to the required group (sys by default)