5

I have an SVG that I need to convert to PDF for printing. How can I achieve this while offering support for the following requirements:

  • CSS fonts
  • Patterns
  • Clip paths
  • CMYK colour profiles
  • Filters
  • CMYK Rasterisation
  • Command line/silent conversion

I have tried many of the popular tools, which I will list below but none of them are particularly successful, always some feature that's not fully supported. I do struggle to understand why it is so difficult to find a decent tool given the length of time that SVG has been support by browsers.

I cannot find a tool that does all of these things. Inkscape comes the closest but fails in patterns and CMYK rasterisation, also had some strange behaviour with clip paths. That said printing as PDF directly from the browser actually produces the best results but doesn't support CMYK and appears to just be one complete rasterised image. However if I could do this silently from command line I'd almost be happy at least.

Anyway the full list of tools/libraries I have tried are as follows:

  • Inkscape
  • ImageMagick/Magical.net
  • Scribus
  • CiaroSVG
  • Mkhtmltopdf
  • TotalCADConverter
  • Windows print to PDF
  • I would suggest converting all the CMYK colors in the SVG to RGB. The editing the SVG part should be straight forward, there are SVG tools out there. But the CMYK to RGB part I'm not sure what the easiest way would be. – Ryan Feb 22 '17 at 18:18
  • @Ryan thanks but even with just RGB, I have yet to find a tool that supports the other features I mentioned. Perhaps you could suggest one? – Kezza Feb 22 '17 at 19:39
  • 2
    Open svg in browser and print the page to pdf – Lynob Feb 22 '17 at 20:22
  • @Lynob Not silent or command line so doesn't meet my requirements – Kezza Feb 22 '17 at 20:27
5

Open SVG in browser and print the page to PDF.

Not silent or command line so doesn't meet my requirements

Use cmdlnprint

$ firefox -print "URL"

Addon for Firefox to automate printing using command line (silent printing). You can print to a normal printer configured at your system or print as a file (pdf, ps or png).

And there are a billion other way/extension to automate any browser or to control it from command line. Selenium might do the job too. That extension above was the first Google search result.

  • Haha, Firefox. Should've guessed. There was me looking for ways to do it with Chrome. Thing is I found chrome extensions etc but they still didn't support the features for some reason came out wrong for one reason or another. Anyway will give it a go and set as answer if works. Thanks – Kezza Feb 22 '17 at 20:42
  • 1
    @Kezza chrome will never work if you want a straightforward extension. Reason is they stop supporting NPAPI, hence no chrome extension will be able to access your pc, so no chrome extension will work from Command line – Lynob Feb 22 '17 at 20:44
  • Ok the files are a bit large compared to other tools, and there seems to be a problem with fonts but this is definitely a Firefox thing as it doesn't display correctly into the browser and I will have to fix this anyway. Definitely does the best job so far and gives me a good place to start more investigation. Thanks – Kezza Feb 22 '17 at 21:07
  • @Kezza glad it worked :) – Lynob Feb 22 '17 at 21:10
1

For people who want it to run truly headlessly, i.e. no X server, try wkhtmltopdf (note that Linux distro packages of it are missing some features, so download from their website). It was designed to work with HTML but uses QT WebKit and so should be able to render SVG. Run with wkhtmltopdf input.svg output.pdf.

wkhtmltopdf also works with inputs located on the internet.

EDIT: This worked for me without any special modifications! screenshot

  • I did try with this tool but it didn't render the SVG – Kezza Feb 27 '17 at 8:03
  • What if you open the SVG in a text editor and add <html><body> on a new first line and </html></body> on a new last line, and try it with the resulting HTML document? ;-) – Nonny Moose Feb 27 '17 at 13:26

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.