Portable Document Format (PDF) was created to be an accurate representation of a source document across platforms and devices. However, it’s a read-only format, not an editable format. As a result, writing annotations on a PDF file usually requires special tools.
In this tutorial, we’ll look at some open-source Linux programs that we can use to write annotations over a PDF, highlight existing text, or insert images. We’ll use each of them to edit the same sample PDF file.
Linux Mint 21 will be our testing environment. So we’ll need to adapt the installation instructions if we’re using a non-Ubuntu based distribution.
$ sudo apt install okular
It offers a toolbar for adding annotations to PDF files, such as highlighting, underlining, squiggles, strikethrough, free text, inline notes, popup notes, drawing, and a variety of predefined messages (approved, confidential, draft, etc.). The official documentation describes all these options in detail. We can activate this toolbar in the Tools menu:
We can save the annotated document either in PDF format or in Okular’s native format, which has the .okular extension. In the first case, Okular embeds the annotations in the PDF. In the second case, it saves the original document and the metadata, i.e., the annotations, separately within the .okular file, which is nothing more than a zip archive:
$ file example.okular example.okular: Zip archive data, at least v2.0 to extract, compression method=deflate $ unzip -l example.okular Archive: example.okular Length Date Time Name --------- ---------- ----- ---- 219 2023-05-18 20:55 content.xml 390582 2023-05-18 20:55 example.pdf 107 2023-05-18 20:55 metadata.xml --------- ------- 390908 3 files
Whether we use PDF or Okular’s format, we’ll be able to edit, add, or delete our annotations later.
Xournal++ allows us to take notes, sketch, and annotate PDF documents. Let’s install it:
$ sudo apt install xournalpp
We can import a PDF file and add our comments, highlights, drawings, and other annotations on top of it, as in the following example:
We can then export the annotated PDF as a new PDF file, but there is no way to edit our annotations in the resulting PDF. If we want to edit our annotations, we need to save the document in the native Xournal++ format, which has a .xopp extension and must be saved along with the original PDF. We can find more information in the official Xournal++ documentation on PDFs.
Evince is GNOME’s default document viewer. If we use another graphical environment, we can still install it:
$ sudo apt install evince
It supports only basic annotations, as in the following example:
- PDFrankenstein converts each PDF page to SVG, the native vector format of Inkscape
- We can choose which page to open with Inkscape
- We can add any Inkscape object on top of the page, but we can’t edit the original page content, which appears as a non-editable layer
- After saving and closing the page, we return to PDFrankenstein
- PDFrankenstein allows us to delete our annotations or to continue adding them to any page
- Finally, we can save the annotated PDF as a new PDF, independent from the original one
$ sudo apt install inkscape poppler-utils qpdf $ wget https://github.com/oxplot/pdfrankenstein/releases/download/v0.9.3/pdfrankenstein_0.9.3_linux_amd64.deb $ sudo dpkg -i ./pdfrankenstein_0.9.3_linux_amd64.deb
This installation doesn’t automatically create a program icon or association with PDF files, so we have to create them manually according to our graphical environment.
Let’s open our example file and try to insert a text annotation and a shape on the first page. Maybe because of a bug, PDFrankenstein 0.93 starts minimized:
If we just want to add annotations or other graphical objects on top of the original PDF, then PDFrankenstein is a reasonable solution. In the next section, we’ll explore the possibility of full PDF editing instead.
6. Full PDF Editing
Tools aimed at complete editing of a PDF allow both annotation and any other editing. However, we must keep in mind that such tools may compromise the original layout of the PDF under various conditions, the first of which is the lack of fonts embedded in the PDF on our machine.
$ pdffonts example.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- AAAAAA+Economica-Regular CID TrueType Identity-H yes yes yes 4 0 BAAAAA+Economica-Bold CID TrueType Identity-H yes yes yes 5 0 CAAAAA+OpenSans-Bold CID TrueType Identity-H yes yes yes 6 0 DAAAAA+OpenSans-Regular CID TrueType Identity-H yes yes yes 7 0
On our test machine, we have the OpenSans font but not Economica. Fortunately, in some cases, we can work around the missing fonts problem, as we’ll see.
There are some major advantages with PDFrankenstein over the use of Inkscape alone. First, Inkscape doesn’t support editing multi-page PDFs, only single pages. Second, the following is the result of opening the file directly in Inkspace using the standard PDF import options:
6.2. LibreOffice Draw
LibreOffice Draw supports multi-page PDF editing and is preinstalled in our testing distribution as well as other distributions. It’s fairly intuitive to use.
There are no import options for converting text to vectors, but it works quite well, even with the lack of fonts. In the following example, we’ve modified the title and added a smiley face over the central image:
LibreOffice Draw allows us to insert objects, such as charts, tables, or formulas, from other LibreOffice applications. We can save what we’ve changed as a new PDF or export to other formats such as SVG, PNG, JPG or HTML.
Scribus is a cross-platform desktop publishing program for creating professional-looking documents such as magazines, books, flyers, brochures, and more. It also includes vector drawing tools, support for many file formats, and the ability to render LaTex and other markup languages.
When installing via apt, we can select all packages with the final wildcard after scribus or omit it to install only the strictly necessary dependencies:
$ sudo apt install scribus*
Scribus fully supports multi-page PDFs and has a text-to-vector import option to work around the missing fonts issue:
Scribus allows us to insert PDF forms and annotations using the default toolbar, which has icons for text annotations, link annotations, 3D annotations, form fields, and buttons. In the animation below, we’ve added a PDF link annotation to the title area, making it a clickable area, and a text annotation that renders as a popup annotation:
In this article, we’ve seen some free and open-source Linux solutions that can easily handle multi-page PDFs, edit them, or simply add annotations.
We’ve learned how to use tools like Okular, Xournal++, Evince, PDFrankenstein, Inkscape, LibreOffice Draw, and Scribus to add comments, highlights, and drawings to PDF files.
These Linux solutions offer a lot of flexibility and control over PDF documents, but we’ve found that sometimes special arrangements are needed if we don’t have the same fonts embedded in the PDF on our machine.