Your First Aspose.Diagram Application - Hello World
Contents
[
Hide
]
This tutorial shows how to create a very first application (Hello World) using Aspose.Diagram' simple API. This simple application creates a Microsoft Visio file with the text ‘Hello World’ in a specified Page.
Creating the Hello World Application
The steps below creates the Hello World application using the Aspose.Diagram API:
- Create an instance of the Diagram class.
- Apply the license:
- If you have purchased a license, then use the license in your application to get access to Aspose.Diagram' full functionality
- If you are using the evaluation version of the component (if you’re using Aspose.Diagram without a license), skip this step.
- Create a new Visio file, or open an existing Visio file.
- Create a new text box.
- Insert the words Hello World! into a text box.
- Generate the modified Microsoft Visio file.
The implementation of the above steps is demonstrated in the examples below.
Code Sample: Creating a New Diagram and Writing Hello World!
The following example opens an existing Microsoft Visio template file named “Basic_Shapes.vss”, inputs “Hello World!” text in the first page and saves the diagram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jpype | |
import asposediagram | |
jpype.startJVM() | |
from asposediagram.api import * | |
lic = License() | |
lic.setLicense("Aspose.Total.Product.Family.lic") | |
diagram = Diagram("Basic_Shapes.vss") | |
# Add a new hello world rectangle shape | |
shapeId = diagram.addShape(4.25, 5.5, 2, 1, "Rectangle", 0) | |
shape = diagram.getPages().getPage(0).getShapes().getShape(shapeId) | |
shape.getText().getValue().add(Txt("Hello World")) | |
# Save diagram in the VSDX format | |
diagram.save("CreateHelloWorldVisio_out.vsdx", SaveFileFormat.VSDX) | |
jpype.shutdownJVM() |