-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying Inkspace for svg conversion tool (as well as rsvg-convert) #8176
Comments
What would be the command for converting on the command line via inkscape? |
I'm not sure I understand the question, but I could suggest for pandoc:
Or are you asking about how to convert with inkscape:
I believe the extension of the export filename determines the destination format (pdf, png, etc.) There is documtation here. |
Is inkscape strictly better than rsvg-convert? Or is it better in some cases and worse in others? If it's strictly better, perhaps we could always use inkscape if available and fall back on rsvg-convert. Then we wouldn't need a new option. |
I think it's the latter. I know that Inkscape has been involved in SVG as a standard for a while, e.g., https://inkscape.org/support-us/svg-standards-work/ Inkscape as a creation tool is very powerful and the things you can create with it are converted well to PDF (maintaining vectors -- there are examples I know of, especially with paths, that But, the tool itself is likely much bigger (it's a pretty big install on windows, 0.5 G for example). I suspect the performance of both will also be different. Given a large batch of SVG files,
I like that idea, but I'm biased in wanting to use Inkscape. It's easy enough to remove |
For the necessary commands see the respective function in the diagram-generator.lua filter. As can be seen there, the whole process is made more complex by having to check for the installed inkscape version, as the parameter names are not the same in v1 and v2. |
If you arrived here because of some SVG produce by mermaid, you can get rid of the foreignObjects by adding |
Regarding the original suggestion, |
to highjack this discussion as well, the @matclab solution did not work for me, as explained here. Alternatively one can use mermaid-cli to export the Mermaid stuff as PDF:
and then use Pandoc to convert it to PDF:
alternatively, if you prefer using mermaid-filter, then change your fences code from ```mermaid
``` to ```{.mermaid format=pdf}
``` and then
please consider that my solution is for Windows OS. On POSIX compatible platforms such as macOS and Linux you need to adapt. |
@fuhrmanator I think an inherently better and more robust solution is to use headless Chromium based internet browsers, such as Google Chrome or Microsoft Edge, in headless mode to convert SVG to PDF. For example see this post. For example
|
Thanks @Foadsf ! That is super useful, and I've used headless Chrome in software testing pipelines. Now, how to make it work in the pandoc pipeline? I'm using tools like Quarto and it defaults to |
I'm totally a fan of your proposal to let the user choose for their SVG converter, but yeah |
I don't want to reopen this issue, because I don't think inkscape is an improvement over rsvg-convert. But headless chrome might be. Feel free to open a new issue, including the command-line invocations that would work for both chrome and edge. (I guess we could always see what is in the path - edge, chrome, chromium, rsvg-convert - and use the best available option.) |
I was ready to open a new issue, and tried some conversions to verify the command-line info. But I got stuck because everything comes out in the PDF as US Letter size (I was able to turn off header/footer with It seems edge/chrome/chromium doesn't have a command-line option to use the SVG's bounding box for the PDF page size. There are some work-arounds (see https://stackoverflow.com/questions/44970113/how-can-i-change-paper-size-in-headless-chrome-print-to-pdf/) if you put the SVG in an HTML document with a CSS setting of the bounding box, but that's seems overly complicated compared to how the other tools work. ChatGPT suggested creating a script that uses Puppeteer (nodejs), which also doesn't seem viable for a pandoc pipeline. @Foadsf did I miss something? Otherwise, without variable-sized PDF output, I can't see this as a good option. |
@fuhrmanator I am no expert here, but I would say manually hardcoding the page/frame size, is not a the best idea. According to this comment, Inkscape has the TBH, I have not tested the headless browser idea much other than this post, but I think if we want to resolve these issues in a canonical way, we need to go upstream and open issues for P.S.1. I see that somebody has already opened an issue here upstream. P.S.2. Boy oh boy, the state of SVG rendering and conversion is really messy. The more I read about it the more I get convinced that SVG was probably a bad choice by the Mermaid team, and other projects such as Inkscape, as the intermediary markup language. Probably they would be better off using something like Postscript P.S.3. Apparently, Mozilla has solved the |
@jgm please check this simple Node.js script. feel free to just include it anywhere you need. More on this here. |
@Foadsf this worked pretty well in my tests, but it produced a two-page PDF for a one-page SVG. About the dependencies: I know nothing about 'puppeteer' - is this dependency something that would need to be installed? |
@jgm I know nothing about Puppeteer either, but this is the same library that Mermaid CLI uses to generate the PDFs, and if I'm not mistaken this is basically equivalent to the proposal shared above about using the headless browser. I'm not sure if there is anything similar to Puppeteer for Haskell, but if someone has Mermaid CLI, they already have Node.js and Puppeteer. Feel free to take the code I shared in the Gist with a WTFPL license and alter it in anyway you like. I think eventually something like this could replace In parallel I believe it should be possible to flatten the and simplify the SVGs that include |
A past Haskell/Google Summer of Code project touched on this, cdp-hs. It should be possible to use that instead of puppeteer. |
Describe your proposed improvement and the problem it solves.
Some SVG files (those with certain foreignObject?) get (better) conversion to PDF (or other destinations) with Inkscape rather than rsvg-convert. It would be good to have a way to specify which SVG converter to use.
Describe alternatives you've considered.
I've considered various filters (gists, python, hs), but they seem to be unmaintained by a community.
ConTeXt apparently supports inkscape (if it's installed), but for my project I can't use ConTeXt.
The text was updated successfully, but these errors were encountered: