Tuesday, January 30, 2024

Editing PDF's in Windows and Linux

One of the main promises of digitization is “going paperless” — using digital (instead of paper) documents for record-keeping and other management processes. To a large extent this has come true, save for one stumbling block: signing documents. While digital signing solutions do exist and are getting more popular, there are still plenty of times when we have to do this ridiculous song-and-dance:

  1. Receive a PDF document by email;
  2. Print the document;
  3. Sign the document;
  4. Scan the document;
  5. Email back the scanned signed document.

Surely there must be a better way.

On Windows, Adobe’s Acrobat Reader includes tools for filling a PDF form, including the option of inserting a scanned signature. The interface can be a little awkward, especially in edge cases such as filling multiple signature fields, but with a little practice it can be made to work quite well.

Unfortunately, Acrobat Reader isn’t available for Linux. You can always run the Windows version in a virtual machine, but that’s rather compute-intensive; another option is installing Acrobat with Wine, but support isn’t perfect at the moment.

What about third-party tools? There are several options, most with their particular downsides:

  • GIMP is an image editor tool with PDF support. It does a great job of converting PDF documents to images, which can then be freely edited — but exporting simply outputs the imported data as images, which degrades document quality and drastically increases file size.
  • LibreOffice Draw can edit PDF files, including the ability to add (signature) images to a document. However it often has problems rendering fonts correctly, leading to format corruption.
  • Okular has perfect rendering support and powerful annotation tools, including the ability to add images to documents as “stamps” — but saving these changes in a format visible by other tools requires printing the modified document to file, which degrades quality and increases file size, sometimes by as much as four times.
  • QPDF is a command-line tool and C++ library for manipulating PDF files. In the case of multi-page documents where only a few have to be edited, it can be used to attenuate the file size issues of the other options, by splicing unmodified pages from the original document with modified ones generated by other tools.
  • Scribus is a desktop publishing application that can import and export PDF files. It can be used to import a document, add text and image fields as needed, then export it back to PDF. The exported documents look perfect, but they are huge — in my experiments a 1MB document ballooned to over 30 MB after exporting.

As of this writing, the one tool that worked perfectly for me is Xournal++, “a handwriting notetaking software with PDF annotation support”. PDF rendering support is excellent, and the UI is about as good as Acrobat’s. The only warning is that you should definitely install the latest stable release, since even slightly outdated versions tend to be a little buggy. This is especially true for Ubuntu LTS and derivatives which tend to trail behind upstream repositories.

To install the latest stable release of Xournal++ to Ubuntu, open a terminal session and enter the commands below:

sudo add-apt-repository ppa:apandada1/xournalpp-stable
sudo apt update
sudo apt install xournalpp

For other distributions, see the project page for details.

Once Xournal++ is installed, PDF files can be opened from the main menu by selecting File -> Open, or by using the Ctrl+O shortcut. Common editor options include:

  • Add Image: Tools -> Image or Shift+Ctrl+I — then click on the location where you want to add an image. A file selection dialog will automatically open. Once the image is added it can be freely moved and scaled. If you want to scale an image while keeping its proportion, click and drag one of the corners of the image bounding box; to scale without maintaining proportion, click and drag from the middle of one of the sides.
  • Add Text: Tools -> Text or Shift+Ctrl+T — then click on the location where you want to add a text box. Font face, size and effects (i.e. italic and / or bold) can be selected from a tool bar drop down. The text box expands in response to the amount of text; line breaks can be added manually.
  • Select Rectangle: Tools -> Select Rectangle or Shift+Ctrl+R — allows previously added elements to be selected, moved and copied / pasted (with Ctrl+C / Ctrl+V).

Notice that when a tool is selected, it remains active until something else is selected — for example, if Add Image is selected, the file selection dialog will open every time you click the document. It’s good practice to manually revert to Select Rectangle every time a new element is added to the document, to avoid surprises.

After completing the desired edits, File -> Export as PDF can be used to export the whole document with the changes. To export just the modifed page(s), you can use File -> Print, select Print to File and enter the desired page(s). Also remember to set the destination file path, which defaults to ~/Documents/output.pdf.

No comments:

Post a Comment