How to convert PNG image to PDF?

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

Post Reply
User avatar
MochiMoppel
Posts: 1119
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

How to convert PNG image to PDF?

Post by MochiMoppel »

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.

User avatar
rcrsn51
Posts: 1224
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 279 times

Re: How to convert PNG image to PDF?

Post by rcrsn51 »

MochiMoppel wrote: Mon Apr 29, 2024 8:02 am

Did this ever work?

Yes. But years ago, busybox dc changed its syntax and PeasyPDF was updated accordingly. Puppy continues to use an obsolete version.

User avatar
rockedge
Site Admin
Posts: 5727
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1999 times
Been thanked: 2102 times
Contact:

Re: How to convert PNG image to PDF?

Post by rockedge »

Puppy continues to use an obsolete version.

Where is the not obsolete version? If it is to be an included application in future Puppy Linux variants it needs to be accessible for a woof-CE build run from a reachable repository.

I'm not hunting it down.

User avatar
Jasper
Posts: 1606
Joined: Wed Sep 07, 2022 1:20 pm
Has thanked: 688 times
Been thanked: 360 times

Re: How to convert PNG image to PDF?

Post by Jasper »

@MochiMoppel

I thought I had compiled the application "Poppler" which has the ability to convert graphic files to pdf.

https://poppler.freedesktop.org/

bigphil
Posts: 80
Joined: Tue Jul 21, 2020 12:56 pm
Location: Sunny Sussex
Has thanked: 10 times
Been thanked: 12 times

Re: How to convert PNG image to PDF?

Post by bigphil »

In Fossapup their is a utility called PuppyPDF - Menu/document.
It can convert .png files to PDF.

User avatar
rcrsn51
Posts: 1224
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 279 times

Re: How to convert PNG image to PDF?

Post by rcrsn51 »

rockedge wrote: Mon Apr 29, 2024 2:38 pm

Where is the not obsolete version? If it is to be an included application in future Puppy Linux variants it needs to be accessible for a woof-CE build run from a reachable repository.

It's in the Starter Kit project, available through Fred's repo. But that version is not Puppy-compatible.

williwaw
Posts: 1608
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 145 times
Been thanked: 293 times

Re: How to convert PNG image to PDF?

Post by williwaw »

rockedge wrote: Mon Apr 29, 2024 2:38 pm

Where is the not obsolete version?

advanced search (gear icon)
peasypdf
rcrsn51

User avatar
rockedge
Site Admin
Posts: 5727
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1999 times
Been thanked: 2102 times
Contact:

Re: How to convert PNG image to PDF?

Post by rockedge »

@rcrsn51 Excellent! Thank you.

User avatar
fredx181
Posts: 2581
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 279 times
Been thanked: 1003 times
Contact:

Re: How to convert PNG image to PDF?

Post by fredx181 »

rcrsn51 wrote: Mon Apr 29, 2024 3:55 pm
rockedge wrote: Mon Apr 29, 2024 2:38 pm

Where is the not obsolete version? If it is to be an included application in future Puppy Linux variants it needs to be accessible for a woof-CE build run from a reachable repository.

It's in the Starter Kit project, available through Fred's repo. But that version is not Puppy-compatible.

This one from my repo probably, (gtk3 supported version .deb package from rcrsn51), perhaps someone can make it "Puppy-compatible" :?: https://github.com/doglinux/book-worm/r ... .0_all.deb
(earlier version 4.6 from 2022 by rcrsn51: (for with gtk2); https://github.com/doglinux/book-worm/r ... .6_all.deb)

User avatar
MochiMoppel
Posts: 1119
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: How to convert PNG image to PDF?

Post by MochiMoppel »

fredx181 wrote: Mon Apr 29, 2024 4:40 pm

This one from my repo probably, (gtk3 supported version .deb package from rcrsn51), perhaps someone can make it "Puppy-compatible" :?: https://github.com/doglinux/book-worm/r ... .0_all.deb

Maybe the same person who made it Puppy-incompatible ;) ?
Xdialog3 .. no idea what this is.
I'm surprised how many versions of PeasyPDF are floating around, all with "# rcrsn51 2011-08-09
# version 2.3 2012-11-15" in the header. Makes it hard to keep track.

User avatar
wizard
Posts: 1612
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2136 times
Been thanked: 505 times

Re: How to convert PNG image to PDF?

Post by wizard »

@rockedge

Here's a peasypdf I hacked to work with BW64:

viewtopic.php?p=109621#p109621

Thanks
wizard

Big pile of OLD computers

User avatar
MochiMoppel
Posts: 1119
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 17 times
Been thanked: 359 times

Re: How to convert PNG image to PDF?

Post by MochiMoppel »

As for the changes in dc:
I suggest to replace this tool with something more "stable", to make the code backward compatible, e.g. with bc (provided the syntax hasn't changed as well).
Even better - and faster - would be to use POSIX compatible shell arithmetic and substitution.

Post Reply

Return to “Users”