PlantUML Text Encoding
PlantUML defines a standardized way to encode diagram text description to a simple string of characters that contains only digits, letters, underscore and minus character.
The goal of such an encoding is to facilitate communication of diagrams through URL (see server).
This encoding includes compression to keep encoded strings as short as possible.
The encoded metadata is stored in the generated PNG, so the diagram source can be extracted from the diagram itself! (see server#metadata).
The following compression algorithms are available:
For example, the following uml text description:
- First was is the Deflate algorithm that gives good results for short diagrams.
- Starting in version 1.2017.20, PlantUML also supports the Brotli algorithm (issue #117) that gives better results for larger diagrams. An initial
0 character is added to the encoded string to indicate Brotli (Deflated data never starts with
- You can also use simple HEX encoding, see below. An initial
~h is added to indicate this encoding.
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
is encoded as:
To achieve such encoding, the text diagram is:
Why not use Base64?
The main reason is historic: this format was not created to be public at first. Now, it's too late to change it. However, the only difference is in character order.
Where in base64 the mapping array for values 0-63 is:
- Encoded in UTF-8
- Compressed using Deflate or Brotli algorithm
- Reencoded in ASCII using a transformation close to base64
For PlantUML, the mapping array for values 0-63 is:
The following diagram:
skinparam backgroundColor #EEEBDC
skinparam handwritten true
skinparam sequenceArrowColor DeepSkyBlue
skinparam sequenceActorBorderColor DeepSkyBlue
skinparam sequenceLifeLineBorderColor blue
skinparam sequenceLifeLineBackgroundColor #A9DCDF
skinparam sequenceParticipantBorderColor DeepSkyBlue
skinparam sequenceParticipantBackgroundColor DodgerBlue
skinparam sequenceParticipantFontName Impact
skinparam sequenceParticipantFontSize 17
skinparam sequenceParticipantFontColor #A9DCDF
skinparam sequenceActorBackgroundColor aqua
skinparam sequenceActorFontColor DeepSkyBlue
skinparam sequenceActorFontSize 17
skinparam sequenceActorFontName Aapex
participant "First Class" as ParticipantA
participant "Second Class" as ParticipantB
participant "Last Class" as ParticipantC
User -> ParticipantA: DoWork
ParticipantA -> ParticipantB: Create Request
ParticipantB -> ParticipantC: DoWork
ParticipantC --> ParticipantB: WorkDone
ParticipantB --> ParticipantA: Request Created
ParticipantA --> User: Done
is compressed to a
You can use
-decodeurl in the command line flags to encode or decode the text.
You will find here some implementation of this encoder:
Simple HEX format
If you find Deflate and Brotli too complex, you can try the HEX format.
In that case, you just have to encode each character in hexadecimal format.
For example :
Alice->Bob : I am using hex
will be turned into:
To indicate the use of HEX format, you must add
~h at the start of the data sent to PlantUML server.
Since there is no compression here, the URL will become very long as the diagram grows.