A command-line tool to transform your PlantUML diagrams into fully editable diagrams.net (formerly draw.io) files. This utility is designed for anyone who wants to seamlessly integrate their documentation workflows.
- Direct Conversion: Convert your
.plantumlfiles to.drawioXML format effortlessly. - Embedded Content: The original PlantUML source code and the rendered SVG are embedded within the diagrams.net XML, allowing for easy access and editing.
- Interactive Diagrams: Double-click the converted diagram in diagrams.net to reveal and edit the PlantUML source. If the PlantUML library is loaded in diagrams.net, changes will update the diagram dynamically.
- Command-Line Utility: Integrate this script into your build processes or use it for quick, one-off conversions.
Before you can use this script, ensure you have the following installed:
-
Java: The script relies on the PlantUML JAR, which requires a Java Runtime Environment. Tested with OpenJDK 21 and Amazon Corretto 17.
-
Graphviz (for Linux users): The
dotcommand, part of thegraphvizpackage, is necessary for rendering certain PlantUML diagrams. If you're on Linux, you can install it with:sudo apt-get install graphviz
-
diagrams.net / draw.io: While not strictly required to run the script, you'll need diagrams.net (desktop application or web) to open and interact with the generated XML files. Tested with diagrams.net ^24.3.1.
The plantuml-to-drawio tool is distributed as a standalone executable.
-
Download the latest release: Visit the releases page and download the appropriate executable for your operating system (e.g.,
plantuml-to-drawio_win.exefor Windows,plantuml-to-drawio_linuxfor Linux, etc.). -
Make it executable (Linux/macOS): If you're on Linux or macOS, you might need to make the downloaded file executable:
chmod +x plantuml-to-drawio_linux # or your downloaded file name -
Place it in your PATH (optional but recommended): For easy access from any directory, move the executable to a directory included in your system's
PATH(e.g.,/usr/local/binon Linux/macOS, or any directory added to yourPathenvironment variable on Windows).
If you're new to PlantUML, here's a simple example to get you started. Save this code in a file named cat-eats-mouse.plantuml:
@startuml
Cat -> Mouse : eats
@endumlNow, use the plantuml-to-drawio command to convert your PlantUML file.
You'll need to provide the input PlantUML file path and specify an output file path using the -o or --output option.
plantuml-to-drawio cat-eats-mouse.plantuml --output cat-eats-mouse.drawioYou can view all available options and their descriptions by running:
plantuml-to-drawio --helpKey Options:
path(positional argument): The path to your.plantumlfile you wish to process.- Example:
plantuml-to-drawio my_diagram.plantuml ...
- Example:
-o, --output PATH(required): Specifies the path where the generated.drawioXML file will be saved.- Example:
... -o output/diagram.drawio
- Example:
-d, --debug(flag): Enable debug mode. Include this flag if you need more verbose output for troubleshooting.
You have a couple of options for opening the generated .drawio file in diagrams.net:
-
Open as a new diagram:
- In diagrams.net, go to
File>Open from>Device... - Select the
cat-eats-mouse.drawiofile.
- In diagrams.net, go to
-
Import into an existing diagram:
- In diagrams.net, open your existing diagram.
- Go to
File>Import from>Device... - Select the
cat-eats-mouse.drawiofile.
This script performs a series of steps to achieve the conversion:
- PlantUML to SVG: Utilizes the PlantUML JAR and Java to convert the plain text PlantUML code into an SVG image.
- SVG Encoding: Encodes the generated SVG data using Base64 for embedding within the XML.
- PlantUML Text Encoding: Encodes the original PlantUML text data to be safe for embedding in XML/HTML/URL formats.
- Dimension Extraction: Parses the SVG data to extract its dimensions (width and height) for proper rendering in diagrams.net.
- Last Modified Date: Retrieves the last modification date of the input PlantUML file to set as the revision date in the diagrams.net XML.
- XML Generation: Constructs the diagrams.net XML file, embedding the encoded SVG and PlantUML text, and outputs it to standard output.
If you wish to build the executable binary from the source code, follow these steps:
-
Make the build script executable:
chmod +x ./build.sh
-
Run the build script:
./build.sh
This will create a
distfolder containing the compiled binary.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
This program is free software.
This script is based on the work of Russell Glaue.