A quick look at adding PDF pages to existing Xournal++ journals
2024-05-10
After talking about Xournal++ as my software of choice for handwritten notes in last weeks article, I noticed that I have never publicly mentioned how to add PDF pages to existing journals, which sadly isn't a functionality provided out of the box by Xournal++. So, let's change that...
When working with PDF backgrounds, there are really three ways to handle them. The easiest is to simply
open the PDF you want to edit with Xournal++, but this limits you to just this single PDF. The second
approach is to open Xournal++, select
Annotate PDF
and open the PDF from there, which at least creates a dedicated .xopp project file, but still isn't
compatible with the hack I'm about to present.
The way to do it
is to go through the
Annotate PDF
menu and select your PDF, but also check the
Attach file to the journal
option, which will create a
filename.xopp.bg.pdf
file alongside your usual journal that stores the background PDF pages.
Since Xournal++ doesn't provide thhe functionality to add pages to this background file after creating it, we have to get a little creative with some BASH scripting. The GNOME file manager Nautilus has support for so-called custom scripts (just like Thunar and most other file explorer on Linux) allowing you to simply select the PDF file you want to append as well as the journal you want to append it to and execute my script from the right-click menu, which makes this janky solution actually rather usuable. Once you have executed the script, simply restart Xournal++ and add your new pages like any other PDF page. Here are some instruction on how to setup this custom script:
-
Make sure you have
poppler-utils
installed, since it provides the terminal-based PDF editing software used by my script -
Navigate to
~/.local/share/nautilus/scripts/
and create a file calledadd-pdf-to-xopp.sh
in the folder -
Added the following content to the script file:
#!/bin/bash
for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
TYPE=$(echo $FILE | grep -P -o ".*\K\..*")
if [[ $TYPE == .xopp ]]
then
TARGET=$(basename $FILE)
TARGET+=".bg.pdf"
else
SOURCES+=$FILE
SOURCES+=" "
fi
done
pdfunite $TARGET $SOURCES .pdfunite-tmp.pdf
mv .pdfunite-tmp.pdf $TARGET -
Make the script executable via
chmod +x ./add-pdf-to-xopp.sh
- Have fun using this hack ;)
I know that this is a rather niche problem, but hopefully it is helpful to at least someone other than me - if so, the time writing it was already worth it. As always, feel free to share your thoughts and experiences in the comments down below and have a lovely day...