4

I have created a simple example plot, which I have as a pdf file. I use Inkscape to create an SVG file. However, the file gets very large, which I think is caused by the black lines. Inkscape draws each line individually. Is there any way to compress the black lines into one element, which in turn should drastically reduce the size of the SVG? Or are there other approaches how to achieve a comparable size to the PDF file (16 KB vs. 310 KB)?

I know it's possible to delete metadata, etc., but that doesn't solve my problem.

Example:

enter image description here

3

I can get the SVG down to 26.5kb if that's any help, without having to resort to using any compressed format.

Here's how I did it.

  1. Open the PDF in Inkscape, select everything and ungroup everything several times.

  2. Select all the separate lines in the long block along the bottom, and do Path > Combine. This get's rid of all the excess paths by merging them all into one single path. In other software sometimes this is called a "compound" path, Inkscape calls it "combined". It's the same thing though.

  3. Do File > Export As, and use "Optimized SVG" as the file type, then in the Optimised SVG Output dialog, set the number of digits to 3 decimal places, and remove the metadata. See settings I used here. Maybe you could get it even smaller by using only 2 decimal places, although accuracy may suffer.

enter image description here

3
  • Thanks, that was already very helpful. I also noticed that it makes a difference whether the PDF is imported via Poppler/Cairo or via the internal library. It seems that the file size can be further reduced by using the internal library. Do you have any suggestions in this regard?
    – carl
    Sep 18 at 21:12
  • 1
    @carl - I just opened the PDF with the default setting "Internal import". Sure you can experiment. I'd say use whatever gets you the best result.
    – Billy Kerr
    Sep 18 at 21:50
  • 1
    @carl - forgot to say that Poppler/Cairo import will covert text to paths, rather than editable text. So that explains the higher file size. But this can be a good thing, if for example a viewer doesn't have the right fonts installed. Text objects contain less data than the corresponding path data. Inkscape's "Internal" import maintains text as text objects, but obviously this will only work if you have the specific fonts installed, otherwise font substitution will occur.
    – Billy Kerr
    Sep 24 at 13:11
2

Instead of saving as 'Inkscape SVG', try 'Optimized SVG' and experimenting with its settings. It strips a lot of redundant information.

There is also 'Compressed Inkscape/Plain SVG (*.svgz)', however it's not guaranteed that other software will support this format.

4
  • Thanks, I have already tried the optimized SVG. That helps to reduce the size a bit. However, it is still relatively much larger than the PDF document already for this simple example plot. This multiplies even more when the plot is more complex.
    – carl
    Sep 18 at 11:45
  • @carl Have you tried the 'Compressed Plain SVG' format I've mentioned? With it I got a file that's even a little smaller than the PDF. If you want to go even further, try first saving as optimized svg, then reopening it in Inkscape and then save again as compressed plain svgz.
    – Xrott
    Sep 18 at 11:59
  • Yes, I considered the compressed version. However, as you already stated it is not guuaranteed that other software will support it. In my case, I am not able to use a *.svgz file.
    – carl
    Sep 18 at 12:27
  • @carl Well, then there is not much else to do. Even your idea of combining all paths doesn't reduce the file size that much. The thing is, SVG is based on XML and PDF on PostScript and XML at its core just is "wordier" than PS.
    – Xrott
    Sep 18 at 12:35
2

PDF is by onset much more compressed than SVG which is verbose indeed. In addition to being more optimal to begin with you whould never compare SVG with PDF directly because the PDF is likely to be compressed. So at minimum you should be comparing a zipped up SVGZ file with the PDF.

So to get an idea how much more compressed PDF is to SVG consider how compact the path tag d attribute is compared to to a bunch of circle and line tags. Well the thing inside that d attribute is PDF. They couldnt even be bothered to make their own system that would fit a xml based language better.

So try to make everything or most things one path and use a compressed version of svg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.