Your First Aspose.Diagram Application - Hello World
Creating the Hello World Application
The steps below creates the Hello World application using the Aspose.Diagram API:
- Créer une instance deDiagram classer.
- Si vous avez une licence, alorsappliquez-le. Si vous utilisez la version d’évaluation, ignorez les lignes de code liées à la licence.
- Créez un nouveau fichier Visio ou ouvrez un fichier Visio existant.
- Créez une nouvelle zone de texte.
- Insérez les motsHello World! dans une zone de texte.
- Générez le fichier Microsoft Visio modifié.
La mise en œuvre des étapes ci-dessus est illustrée dans les exemples ci-dessous.
Exemple de code : création d’un nouveau Diagram
The following example creates a new diagram from the scratch, writes Hello World! on the first page and saves the Visio file.
// 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); |
Exemple de code : ouverture d’un fichier existant
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.
// 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); |