languitar / drawio-batch

Command line converter for draw.io diagrams
65 stars 12 forks source link

Support converting to svg #5

Closed evisong closed 5 years ago

evisong commented 6 years ago

Hi,

I've been integrating drawio-batch into a book authoring project, aiming to convert source draw.io XML diagrams to images, and then used in markdown documents.

I found that even using Export in draw.io, the exported PNG would be a little fuzzy, but the exported SVG is perfectly as sharp as the source diagram.

I've tried drawio-batch my-diagram.xml my-diagram.svg, it prompts an error:

Converting my-diagram.xml ...
Error: Unsupported screenshot mime type: image/svg+xml
    at assert (.../node_modules/puppeteer/lib/helper.js:251:11)
    at Page.screenshot (.../node_modules/puppeteer/lib/Page.js:757:7)
    at .../node_modules/drawio-batch/drawio-batch.js:76:18
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Is it possible to add the svg support?

Thanks.

chbndrhnns commented 6 years ago

I was also wondering about SVG export. Is it just a matter of adding the command line options or is SVG export fundamentally different from the pixel formats?

languitar commented 6 years ago

Oh, interesting, I didn't receive any notifications for this issue...

The thing is that I am using puppeteer (a wrapped headless chrome) for rendering and there is no method to render an SVG directly. It seems that the export backend of drawio supports SVG export though. I will have to check if there is a way to handle this. But it is not as straight-forward as other pixel formats.

languitar commented 6 years ago

@evisong as a workaround for your current issues: you can either increase the size of the PNG using --scale or use a PDF export, which you can convert to SVG using inkscape.

davidjgraph commented 5 years ago

SVG export is fully client-side.

languitar commented 5 years ago

@davidjgraph could you give me a hint where to start?

languitar commented 5 years ago

I think i found the relevant code path. However, supporting SVG in drawio-batch is pretty hard as this uses a completely different mechanism and is not based on the backend. Instead, I would have to construct the graph internally in the export script. That's a lot more work... :/ I think I will skip this for the moment.

languitar commented 5 years ago

Actually, I found a way to make this work with the current export code.