Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed JPG data properly in PDF files generated by Inkscape

Tags:

pdf

jpeg

inkscape

There is a bug in Inkscape where JPEG images included in an SVG document are embedded as bitmaps rather than JPEG when exporting to PDF files.

The result is a huge increase in file size. For example, I have a simple SVG drawing which includes a 2 MB JPEG image; exporting to PDF results in a 14 MB file.

I am looking for a workaround. Is there a way to fix the resulting PDF by inserting the correctly-encoded JPG image, perhaps via some sort of pdftk trickery?

(In my case, the resulting PDF will be included as a figure in a LaTeX document rendered with pdflatex, so there may be workarounds other than directly fixing the PDF generated by Inkscape.)

like image 960
nibot Avatar asked Oct 10 '22 12:10

nibot


2 Answers

One kludge is to use pdf2ps followed by ps2pdf, which will re-encode the bitmap data as JPEG:

pdf2ps made-by-inkscape.pdf foo.ps
ps2pdf foo.ps smaller-file.pdf

For my test case, the file sizes were:

original JPEG           2.1M
made-by-inkscape.pdf   15M
foo.ps                104M
smaller-file.pdf        1.5M

But of course, this involves re-encoding the JPEG data, which is best avoided.

like image 93
nibot Avatar answered Oct 13 '22 10:10

nibot


I found that with Inkscape 0.48.1 exporting to EPS instead, and passing the resulting EPS file to the epstopdf script, produces good results. PNG/JPG files stay PNG/JPG within the PDF file, fonts look alright, etc.

like image 26
Samuel Audet Avatar answered Oct 13 '22 09:10

Samuel Audet