Creating SVG image from a diagram and PlantUML and Java API
Source code name: "uml_diagram1_svg.py"
Programming language: Python
Topic: Plots/Diagrams
DMelt Version 2.2. Last modified: 02/13/1972. License: Pro
https://datamelt.org/code/cache/uml_diagram1_svg_7926.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from net.sourceforge.plantuml import SourceStringReader
from java.io import ByteArrayOutputStream
from net.sourceforge.plantuml import FileFormatOption,FileFormat
from java.lang import String
from java.nio.charset import Charset
source = "@startuml\n scale 600*400\n Bob -> Alice : hello\n @enduml\n";
reader=SourceStringReader(source)

os=ByteArrayOutputStream();
# Write the first image to "os"
desc = reader.generateImage(os, FileFormatOption(FileFormat.SVG));
os.close()

#The XML is stored into svg
svg=String(os.toByteArray(), Charset.forName("UTF-8"))

xf="diagram.svg" # write to file 
f=open(xf,"w")
f.write(svg.toString())
f.close()
print "Making:",xf



You see the box below because you did not login.