Command line conversion to PDF tool

987 views
Skip to first unread message

Johannes Wienke

unread,
Aug 18, 2017, 7:11:34 AM8/18/17
to draw.io
With drawio desktop, would it be possible to provide a mode that just converts an xml graph document to a common format like PDF without the need for a GUI. This would allow to automate generating world-readable files from drawio graphs.

Cheers,
Johannes

Gaudenz Alder

unread,
Aug 23, 2017, 3:15:07 AM8/23/17
to draw.io
The desktop app uses exp.draw.io to generate the PDF, so wget could be used to script that, or, for public files from URLs, exp.draw.io can be used to generate images or PDFs as follows: https://exp.draw.io/ImageExport4/export?format=[png|pdf]&url=encoded_url_of_file
Please do not use these servers for large scale automated exports. Contact sup...@draw.io to run your own instance instead.

Johannes Wienke

unread,
Sep 1, 2017, 5:00:00 AM9/1/17
to draw.io
Hi,

seems I missed your reply mail.


Am Mittwoch, 23. August 2017 09:15:07 UTC+2 schrieb Gaudenz Alder:
The desktop app uses exp.draw.io to generate the PDF, so wget could be used to script that, or, for public files from URLs, exp.draw.io can be used to generate images or PDFs as follows: https://exp.draw.io/ImageExport4/export?format=[png|pdf]&url=encoded_url_of_file
Please do not use these servers for large scale automated exports. Contact sup...@draw.io to run your own instance instead.

So there is Java code in the background rendering the PDF? Or how is it technically solved? Would be cool to extract this into a standalone converter so that everything works offline.

Johannes

Gaudenz Alder

unread,
Sep 1, 2017, 5:26:49 AM9/1/17
to draw.io
Yes, there is Java code that uses PhantomJS for rendering the PDF (or PNG).

Johannes Wienke

unread,
Nov 6, 2017, 3:50:07 PM11/6/17
to draw.io
Getting back on this one...


Am Freitag, 1. September 2017 11:26:49 UTC+2 schrieb Gaudenz Alder:
Yes, there is Java code that uses PhantomJS for rendering the PDF (or PNG).

Where is this code accessible? Maybe I have some spare time to wrap it as a command line program for people who want to automate file exports.

David Benson

unread,
Nov 8, 2017, 9:37:30 PM11/8/17
to draw.io

Johannes Wienke

unread,
Nov 9, 2017, 3:00:55 PM11/9/17
to David Benson, draw.io
Am 09.11.17 um 03:37 schrieb David Benson:
> https://bitbucket.org/jgraph/draw-image-export

Great! I have hacked together a python wrapper around the original
export code that calls PhantomJS and uses an inlined version of the
original export2.html page for offline rendering.

The code is available here:
https://github.com/languitar/drawio-batch

Hope this helps someone

Johannes

signature.asc

David Benson

unread,
Nov 14, 2017, 6:28:35 PM11/14/17
to draw.io
Nice! Thanks for sharing.

Андрей Стрелков

unread,
Dec 13, 2017, 11:14:17 AM12/13/17
to draw.io
Do I understand correctly that with your solution, you can produce save in PNG or PDF format on your own offline server where you installed draw.io

пятница, 10 ноября 2017 г., 0:00:55 UTC+4 пользователь Johannes Wienke написал:

Johannes Wienke

unread,
Dec 13, 2017, 4:24:36 PM12/13/17
to Андрей Стрелков, draw.io
Am 13.12.17 um 17:14 schrieb Андрей Стрелков:
> Do I understand correctly that with your solution, you can produce save in
> PNG or PDF format on your own offline server where you installed draw.io

Why a server? You can do this on every computer. It's just a command
line tool.

It might still be that some resources are downloaded on demand as some
of HTML and javascript used for rendering might depend on remote stuff.
I have not yet worked around that,

Johannes

signature.asc

Johannes Wienke

unread,
Apr 4, 2018, 3:47:59 PM4/4/18
to draw.io
Just to let you know: I have just completely rewritten drawio-batch based on JavaScript to get rid of the dying phantomjs. Instead, it uses headless chrome now via puppeteer.

Maybe that is also of interest for the webapp? The transition to Chrome wasn't hard. It only removes support for some (ancient) image formats.

David Benson

unread,
Apr 4, 2018, 3:49:09 PM4/4/18
to draw.io
Cool, we did the same thing with the image export backend, https://github.com/jgraph/draw-image-export2 :).

Johannes Wienke

unread,
Apr 5, 2018, 4:51:06 AM4/5/18
to David Benson, draw.io
:D so wouldn't there be a chance so simply merge these projects somehow?
Currently I heavily rely on the internal structure of the drawio git
repository and the availability of the old export stuff in there. If
anything changes on your side, I have to figure out what happened...

Sai Yanamandra

unread,
Jul 12, 2018, 5:35:54 AM7/12/18
to draw.io
Thanks for sharing this. This package was really helpful for me in generating diagrams (pdf) locally from XML using draw.io automatically

Regards,
-Sai.
Reply all
Reply to author
Forward
0 new messages