I need to render my plantUML diagrams from command line using PlantUML server as renderer. This can be done in 3 steps:
- Create text file containing the encoded diagram.
- Send the http request to PlantUML server with URL containing the encoded diagram.
- Download the rendered image.
To encode a diagram (for example “alice.pu”), I use following command:
cat alice.pu | gzip | base64 | tr -d '\n' > encoded_alice.txt
To send the encoded diagram to PlantUML server I do:
ENCODED=$(cat encoded_alice.txt)
URL=http://www.plantuml.com/plantuml/png/$ENCODED
To download the PNG image, I do:
curl -o alice.png "$URL"
Unfortunately, I receive error related to the encoding:
“… It looks like your plugin using HUFFMAN encoding. This means you have to add a header ~1 to your data…”
Adding ~1 to the encoded diagram does NOT help.
When I try to render a simple example diagram:
@startuml alice
Alice -> Bob: test
@enduml
The first command from above (cat alice.pu | gzip | base64 | tr -d '\n' > encoded_alice.txt)
produces following encoded_alice.txt file:
“H4sIAAAAAAAAA3MoLkksKinNzVFIzMlMTuXlcgRRCrp2Ck75SVYKJanFJbxcDql5KUAlACX8hJ0sAAAA”
Which does not work and shows the error from above.
If I copy/paste the example diagram into browser on PlantUML server, the diagram is rendered successfully, and the browser shows me the encoded URL as:
www.plantuml.com/plantuml/png/SoWkIImgAStDuNBCoKnELT2rKt3AJx9IA4ajBk5oICrB0Ke10000
So, the diagram is encoded as
“SoWkIImgAStDuNBCoKnELT2rKt3AJx9IA4ajBk5oICrB0Ke10000”
This encoding works from command line as well: when I put the text
“SoWkIImgAStDuNBCoKnELT2rKt3AJx9IA4ajBk5oICrB0Ke10000”
into the “encoded_alice.txt” , the rendering works and I can download rendered images from command line.
My question is: how can I generate the proper encoding of diagrams so that the server can read the encoding and render the diagram? In other words, how must I change the command:
cat alice.pu | gzip | base64 | tr -d '\n' > encoded_alice.txt
to produce proper encoding that PlantUML server can understand?