SVG support #209

Open
opened 2025-04-15 10:04:42 +00:00 by dreua · 1 comment

I'm prepared to take no as an answer but it may be still be useful to document this.

There are actually two very different ways to render an svg to PDF:

  1. Ideally you keep it a vector based graphic. PDF seems to support similar graphic elements. I've used inkscape with one example file and got good results. (With the gui or cli: inkscape in.svg -o out.pdf) I assume using inkscape as a dependency in img2pdf is not feasible, maybe there is a smaller library (cairo?) which could be used instead.
  2. Rasterization might be easier and could still be useful in some circumstances. From what I read in another issue, img2pdf uses pillow for image formats. There is an open issue in pillow for svg support. The lunasvg library referenced there looks promising.
I'm prepared to take no as an answer but it may be still be useful to document this. There are actually two very different ways to render an svg to PDF: 1) Ideally you keep it a vector based graphic. PDF seems to support similar graphic elements. I've used inkscape with one example file and got good results. (With the gui or cli: `inkscape in.svg -o out.pdf`) I assume using inkscape as a dependency in img2pdf is not feasible, maybe there is a smaller library (cairo?) which could be used instead. 2) Rasterization might be easier and could still be useful in some circumstances. From what I read in another issue, img2pdf uses pillow for image formats. There is an [open issue](https://github.com/python-pillow/Pillow/issues/3509) in pillow for svg support. The [lunasvg](https://github.com/sammycage/lunasvg) library referenced there looks promising.
Owner

As you pointed out, you can already convert svg to pdf today by just using inkscape. So there is no need for img2pdf to be able to do this as well. The main purpose of the existence of img2pdf is the assurance that it is lossless. If you don't need lossless, then there are plenty other tools (like imagemagick) that can do the same job. This also means that rasterization is not an option. One problem of converting SVG to PDF is, that some SVG features are just not supported by PDF so the conversion will be lossy.

As you pointed out, you can already convert svg to pdf today by just using inkscape. So there is no need for img2pdf to be able to do this as well. The main purpose of the existence of img2pdf is the assurance that it is lossless. If you don't need lossless, then there are plenty other tools (like imagemagick) that can do the same job. This also means that rasterization is not an option. One problem of converting SVG to PDF is, that some SVG features are just not supported by PDF so the conversion will be lossy.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#209
No description provided.