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:
- Crear una instancia de laDiagram clase.
- Si tiene una licencia, entoncesapliquelo. Si está utilizando la versión de evaluación, omita las líneas de código relacionadas con la licencia.
- Cree un nuevo archivo Visio o abra un archivo Visio existente.
- Crear un nuevo cuadro de texto.
- Inserta las palabrasHello World! en un cuadro de texto.
- Genere el archivo Microsoft Visio modificado.
La implementación de los pasos anteriores se demuestra en los siguientes ejemplos.
Ejemplo de código: creación de un nuevo Diagram
The following example creates a new diagram from the scratch, writes Hello World! on the first page and saves the Visio file.
This file contains hidden or 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
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateNewVisio.class); | |
// initialize a Diagram class | |
Diagram diagram = new Diagram(); | |
// save diagram in the VSDX format | |
diagram.save(dataDir + "CreateNewVisio_Out.vsdx", SaveFileFormat.VSDX); |
Ejemplo de código: abrir un archivo existente
The following example opens an existing Microsoft Visio template file named “Sample.vsdx”, inputs “Hello World!” text in the first page and saves the diagram.
This file contains hidden or 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
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ReadVisioDiagram.class); | |
// Open the stream. Read only access is enough for Aspose.Diagram to load a diagram. | |
InputStream stream = new FileInputStream(dataDir + "Drawing1.vsdx"); | |
//Call the diagram constructor to load diagram from a VSDX stream | |
Diagram vsdDiagram = new Diagram(stream); | |
stream.close(); | |
//Call the diagram constructor to load diagram from a VDX file | |
Diagram vdxDiagram = new Diagram(dataDir + "Drawing1.vdx"); | |
/* | |
* Call diagram constructor to load diagram from a VSS file | |
* providing load file format | |
*/ | |
Diagram vssDiagram = new Diagram(dataDir + "Basic.vss", LoadFileFormat.VSS); | |
/* | |
* Call diagram constructor to load diagram from a VSX file | |
* providing load options | |
*/ | |
LoadOptions loadOptions = new LoadOptions(LoadFileFormat.VSX); | |
Diagram vsxDiagram = new Diagram(dataDir + "Drawing1.vsx", loadOptions); |