Programmatically generate PNG from diagram XML

442 views
Skip to first unread message

Sayan

unread,
May 16, 2023, 2:07:31 PM5/16/23
to draw.io Q&A
Hello,

I am trying to generate a PNG for a drawio diagram from the diagram's XML. Essentially, I start with valid XML for a drawio diagram, I modify a value field in the XML slightly, and I would like to regenerate the diagram's PNG to reflect this change using (python) code.

Does anyone have any suggestions or advice on how to do this sort of thing?

Thanks

draw.io Q&A

unread,
May 19, 2023, 12:36:51 PM5/19/23
to draw.io Q&A
Use the desktop build with command line.

Sayan

unread,
May 25, 2023, 5:20:11 PM5/25/23
to draw.io Q&A
I did this and was able to generate a new PNG, but when I try to open the PNG in an editor, the editor is blank and the diagram does not show up. It seems the diagram's contents are not being passed to the editor.

Sayan

unread,
May 25, 2023, 6:38:55 PM5/25/23
to draw.io Q&A

Update: I found the solution to this problem. You have to set the embed diagram flag (-e) when running the command in the command line to embed the diagram. This allows the diagram to be editable.

Sayan Sisodiya

unread,
Jun 26, 2023, 1:20:09 PM6/26/23
to draw.io Q&A
I have a follow-up question regarding this same process: the requirements of my project have changed, and I would like to be able to do this process of generating a PNG from XML in a Docker container instead of interacting with the CLI via an os.system() call in Python. Is there a way I could get this same process to work using an instance of Draw.io hosted in a Docker container? Any suggestions are appreciated.

Thanks

Reply all
Reply to author
Forward
0 new messages