How to save PDF with JPG embedded

Post questions on how to use or achieve an effect in Inkscape.
etrader
Posts: 25
Joined: Thu Mar 14, 2013 11:45 pm

How to save PDF with JPG embedded

Postby etrader » Mon Jun 16, 2014 5:46 pm

I've completed several projects in inkescape, which include many JPEG files embedded. When I saved the files as PDF, I just found that inkscape saves embedded JPG/JPEG files as bitmap. This extremely increase the sizes of PDF files. Since these projects (PDF files) should be distributed via email, it is extremely important to minimize the size of PDF files.

Is there any way to save PDF with embedded JPG instead of bitmap? or minimize the PDF size by converting back the bitmap to lightweight jpg?

I wonder why inkscape does not have this feature to save PDF with embedded JPG. There should be at least a hack to do so.

Lazur
Posts: 4717
Joined: Tue Jun 14, 2016 10:38 am

Re: How to save PDF with JPG embedded

Postby Lazur » Mon Jun 16, 2014 8:04 pm

Hello,
your description is a bit confusing.
Do you mean bitmap as bmp?
As far as I know all raster elements are saved with jpeg compression,
meaning all embedded parts ARE jpegs no matter what you do.
Which is a shame, since pdf is the most reliable format for printing, and that compression is lossy.

On the other hand, inkscape doesn't have the ability to set that compression
(at least in the save as panel, maybe those who can compile inkscape can hack other compression rates as well.)
You could try some pdf printers like bullzip or cutepdf, to make pdf copies from your files.
They have some options to save with bigger compressions.

etrader
Posts: 25
Joined: Thu Mar 14, 2013 11:45 pm

Re: How to save PDF with JPG embedded

Postby etrader » Wed Jun 18, 2014 10:21 pm

I don't think so. I attach an example.

I have a simple JPEG file with size 20.1 KB
test.jpeg
Original JPEG
test.jpeg (19.65 KiB) Viewed 1722 times

when embedding it into a blank inkscape SVG file, the size of SVG file is 20.2 KB
test.svg
Inkscape SVG
(19.76 KiB) Downloaded 220 times

but if saving it as PDF, the size is 97.6 KB
test.pdf
Saved as PDF
(95.35 KiB) Downloaded 227 times

User avatar
ragstian
Posts: 1181
Joined: Thu Oct 11, 2012 2:44 am
Location: Stavanger-Norway

Re: How to save PDF with JPG embedded

Postby ragstian » Wed Jun 18, 2014 11:43 pm

Hi.

Lazur Urh;
As far as I know all raster elements are saved with jpeg compression,
meaning all embedded parts ARE jpegs no matter what you do.
Which is a shame, since pdf is the most reliable format for printing, and that compression is lossy.

As far as I know - this is not correct, (I might be wrong - has happened before!).
If you open the XML editor and inspect the embedded image you will see it's actually embedded as a lossless png image encoded by 64bit ascii encoding.

It's relatively easy to copy the encoded text (from the XML editor in Inkscape) and decode it back into an image using python (or any other programming language).
The 'extracted' text from the 'pdf' example is 109656 bytes in size.
When it's saved in the pdf file it is compressed using the 'FlateDecode' filter- that's why the pdf file is slightly smaller in size.
The 'compressed' part of the pdf file is 96337 bytes - the whole pdf file is 97639 bytes.
(this part can be 'decompressed' as well using python; http://binaryhax0r.blogspot.com/2010/06/flatedecode-decoder.html)

By importing the PDF example (in inkscape) and clear the 'Embed Images' 'tickbox' the embedded image(s) will be saved as png file(s) to your disk,
this happens automatically when importing (this is a nice way to 'extract' all images from a PDF file!).

RGDS
Ragnar
Good Luck!
( ͡° ͜ʖ ͡°)
RGDS
Ragnar


Return to “Help with using Inkscape”