Multilingual Wiki Documentation

You are currently using syntax.
In an attempt to improve PlantUML documentation...
Please do not use this website for your own diagrams.
You can click here and use the online server here for your own documentation.

Wiki Toc    View page history    Add new chapter    Reorder page    Raw


PlantUMLをJavaから呼び出す

Calling PlantUML from Java

plantuml.jarをクラスパスに追加すれば、PlantUMLを簡単に他のコードに統合することができます。
You can easily integrate PlantUML with your own code by adding plantuml.jar in your classpath.

文字列からのPNG生成

PNG generation from a String

図の説明がString に格納されている場合、SourceStringReader クラスを使って何らかのPNGファイルを生成することができます。

import net.sourceforge.plantuml.SourceStringReader;
OutputStream png = ...;
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";

SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.outputImage(png).getDescription();
// Return a null string if no generation

If your diagram description is stored in a String, you can use the SourceStringReader class to generate some PNG file.

import net.sourceforge.plantuml.SourceStringReader;
OutputStream png = ...;
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";

SourceStringReader reader = new SourceStringReader(source);
// Write the first image to "png"
String desc = reader.outputImage(png).getDescription();
// Return a null string if no generation

FileからPNGを生成する

PNG generation from a File

ダイアグラムの記述をFileとして持っている場合は、SourceFileReaderを使用してPNGファイルを生成します。

File source = ...;
SourceFileReader reader = new SourceFileReader(source);
List<GeneratedImage> list = reader.getGeneratedImages();
// Generated files
File png = list.get(0).getPngFile();

If your diagram description is stored in a File, you can use the SourceFileReader class to generate some PNG file.

File source = ...;
SourceFileReader reader = new SourceFileReader(source);
List<GeneratedImage> list = reader.getGeneratedImages();
// Generated files
File png = list.get(0).getPngFile();

StringからSVGを生成する

SVG generation from a String

ダイアグラムの記述をStringとして持っている場合は、SourceStringReaderを使用してSVGファイルを生成します。

String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";

SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();

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

If your diagram description is stored in a String, you can use the SourceStringReader class to generate some SVG file.

String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";

SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();

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


Please report any bugs to plantuml@gmail.com or here.
This website is still in beta testing.