One workaround is to split the image generation and the PDF conversion. First convert the images via convert
to A4@300dpi (i.e. 3508x2479), then use sam2p to convert them to PDF and then use sam2p_pdf_scale to convert them to A4.
convert -rotate "90>" -scale 3508x2479 -border 64x64 -bordercolor white in.png out.png
sam2p out.png out.pdf
sam2p_pdf_scale 595 842 out.pdf
Edit: A more complete script:
#!/bin/sh
A4_WIDTH=2479
A4_HEIGHT=3508
H_MARGIN=64
V_MARGIN=64
WIDTH=$((${A4_WIDTH} - ${H_MARGIN} * 2))
HEIGHT=$((${A4_HEIGHT} - ${V_MARGIN} * 2))
for i in "$@"; do
TMP="/tmp/$(uuidgen).png"
echo "$i"
convert \
-rotate "90>" \
-scale "${WIDTH}x${HEIGHT}" \
-border "${H_MARGIN}x${V_MARGIN}" -bordercolor white \
-gravity center \
-extent "${A4_WIDTH}x${A4_HEIGHT}" \
-gravity center \
-font helvetica -pointsize 80 \
-fill white -draw \
"push graphic-context
translate $((${A4_WIDTH}/2 - 160)), 0
rotate 90
text -2,-2 '$i'
text -2,2 '$i'
text 2,-2 '$i'
text 2,2 '$i'
pop graphic-context
" \
-fill black -draw \
"push graphic-context
translate $((${A4_WIDTH}/2 - 160)), 0
rotate 90
text 0,0 '$i'
pop graphic-context
" \
"$i" "$TMP"
sam2p "$TMP" "${i}.pdf"
sam2p_pdf_scale 595 842 "${i}.pdf"
done
# EOF #
My recommendation is Xournal
and its actively developed fork, Xournal++
. Here are the instructions.
Install (for Xournal):
sudo apt-get install xournal
For Xournal++ you can use either the stable PPA,
sudo add-apt-repository ppa:apandada1/xournalpp-stable
sudo apt update
sudo apt install xournalpp
or the flatpak,
flatpak install flathub com.github.xournalpp.xournalpp
Run xournal
or xournal++
, click File
>Annotate PDF
, choose your PDF file.
Now, go to where you need to add your signature and click Tools
>Image
(or the "Image" toolbar icon), then click where you want to add the image. An image selection dialog appears, select your image.
Xournal's insert image is a great addition but not polished. As soon as you add the image make sure to resize it and move it to where you want. For resize there's no ability to ensure the proportions stay the same. Just eye it. Once you are done, it is in its own layer, which you cannot change. If you don't like how it ends up delete that layer and start again.
One handy thing is that you can use ctrl-c
as soon as you resize it and then ctrl-v
the next time you need to insert your image. Assuming you want the same size image this will save you some time.
When you are done choose File
->Export to PDF
to get it back into the PDF format I assume you'll want for sending your signed doc.
Note: A downside to Xournal is the finished document looks like the fonts are converted to an image. Fonts are no longer as crisp. Still it looks better than if you printed and rescanned and is much faster. [Note: in my most recent experience it seems this problem has been solved. Maybe I just got lucky with the particular fonts used. Please leave a comment abt your experience and I'll update accordingly.] This issue seems to be fixed in Xournal++ version 1.0.20.
Best Answer
OK well, I did some more research and although tohuwawohu's method does work, I found it easier to use a program called pdftoppm to achieve what I wanted done. Since I am pretty much a layperson when it comes to using command line apps, I will do my best to explain how I got this to work for me.
Navigate to the folder containing the .pdf you wish to edit and open a terminal there. I did this by using the sample command:
Let's say the file I want to edit is called Sample.pdf What I want to do is use pdftoppm to create image files of each page of the .pdf. Several formats can be chosen (see the man pages link above) but I prefer to use .png. The basic command looks like this:
or in the example above:
This command creates an image file of each page in the same folder as the original .pdf file with names like Sample-01.png, Sample-02.png and so on. I have tried it with the .png and .jpeg extensions successfully. .jpg is apparently not supported.
Then I just use Archive Manager by selecting all the newly-created image files, right-clicking, and choosing "Compress" from the context menu. I then choose the archive format I prefer (in this case .cbz or Comic Book Zip) and create the new archive.
Now I have a shiny new .cbz file called Sample.cbz which I can then view with my Comix reader!
Hopefully what I have posted above makes enough sense that someone else can learn from it. If I need to change it in any way please let me know.