My tax office requires all attachments to be in PDF format. I now have various image files in PNG format which I want to convert.
The challenge: The resulting PDFs should have exactly the same dimensions as the source files. Normally PDF printing/converting offers to select a page size, e.g. A4 or letter, and an option to resize the image to the page size. I want the opposite, I want the page size to resize to the image size. A 600x400px image should result in a 600x400px PDF when displayed at 100% in a PDF viewer.
More challenges: Using only tools that are already installed. I'm using BW64 10.0.6 , so often recommended convert or img2pdf are out of the race. Command line tools, if possible.
It's more difficult than I expected.
So far I had success with Abiword and CUPS printing, but the process is tedious and involves defining a page layout or a custom size exactly as large as the image.
Something that works great is inkscape. Not installed but I have an AppImage saved outside of the main sfs and a symlink to this AppImage in my PATH. The command inkscape --export-type="pdf" my_file.png
will create a file my_file.png.pdf , with exactly the same dimension. It's also the only tool I know that would convert SVG to PDF.
Finally I tried PeasyPDF, which has a long history in Puppy but hasn't been maintained since its last version 4.2.(here the download page)
@radky has made some changes to the code so that it runs in BW64. For my purposes the "Convert" tool looks promising, however the code contains a syntax error and happily produces an empty PDF file when choosing a "Custom" page size. Did this ever work?
Let's fix it:
Find the lines
Code: Select all
INWIDTH=$(dc $PIXWIDTH $CUSTOMDPI / p) #inches
INHEIGHT=$(dc $PIXHEIGHT $CUSTOMDPI / p)
and change to
Code: Select all
INWIDTH=$(dc -e"2k $PIXWIDTH $CUSTOMDPI / p")
INHEIGHT=$(dc -e"2k $PIXHEIGHT $CUSTOMDPI / p")
In order to create a PDF with same size on screen as the image the dpi value for "Custom" needs to be changed.
Let's set "Custom" to 96dpi, the de-facto standard in all Puppies
and "Custom+" to 48dpi, increasing size to 200% of original
and "Custom-" to 192dpi, decreasing size to 50% of original:
Code: Select all
if [ "$PAGESIZE" = "$(gettext 'Custom')" ]; then
CUSTOMDPI=96;
elif [ "$PAGESIZE" = "$(gettext 'Custom+')" ]; then
CUSTOMDPI=48;
elif [ "$PAGESIZE" = "$(gettext 'Custom-')" ]; then
CUSTOMDPI=192;
else
CUSTOMMODE="no"
fi
BW64 defaults to gtkdialog compiled forGTK3. If the drop down list doesn't work, the original gtkdialog3
in the last line needs to be changed to gtk2dialog
.
That's all to achieve my goal. Making PeasyPDF more flexible and user friendly is another goal, but I leave this for a rainy day.