// 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.getSharedDataDir(CreateMasterfromScratch.class) + "Masters/"; // create a new template Diagram diagram = new Diagram(); // add master diagram.getMasters().add(createMaster(101, "Regular", dataDir + "icon.png")); // save template diagram.save(dataDir + "template_Out.vssx", SaveFileFormat.VSSX); // create master public static Master createMaster(final int masterId, final String name, String file) throws Exception { // set master properties Master ms = new Master(); ms.setID(masterId); ms.setName(name); ms.setIconSize(1); ms.setAlignName(2); ms.setMatchByName(0); ms.setIconUpdate(BOOL.TRUE); ms.setPatternFlags(0); ms.setHidden(0); // set master's shape properties final Shape shape = new Shape(); ms.getShapes().add(shape); final double width = 0.5443889263424177; final double height = 0.432916947568133; shape.setID(5); shape.setType(TypeValue.FOREIGN); shape.getXForm().getPinX().setValue(0.2221944631712089); shape.getXForm().getPinY().setValue(0.1666458473784065); shape.getXForm().getWidth().setValue(width); shape.getXForm().getHeight().setValue(height); shape.getXForm().getLocPinX().getUfe().setF("Width*0.5"); shape.getXForm().getLocPinY().getUfe().setF("Height*0.5"); shape.getXForm().getResizeMode().setValue(0); shape.getTextXForm().getTxtPinY().getUfe().setF("-TxtHeight/2"); shape.getTextXForm().getTxtWidth().getUfe().setF("TEXTWIDTH(TheText)"); shape.getTextXForm().getTxtHeight().getUfe().setF("TEXTHEIGHT(TheText, TxtWidth)"); shape.getForeign().getImgOffsetX().setValue(0); shape.getForeign().getImgOffsetY().setValue(0); shape.getForeign().getImgWidth().setValue(width); shape.getForeign().getImgHeight().setValue(height); // set connection properties final Connection connection = new Connection(); shape.getConnections().add(connection); connection.setID(1); connection.setNameU("All"); connection.getX().setValue(0.22); connection.getX().getUfe().setF("Width*0.5"); connection.getY().setValue(0.16); connection.getY().getUfe().setF("Height*0.5"); connection.getDirX().setValue(0); connection.getDirY().setValue(0); connection.getType().setValue(0); connection.getAutoGen().setValue(BOOL.FALSE); connection.getPrompt().getUfe().setF("No Formula"); shape.getForeignData().setForeignType(ForeignType.BITMAP); shape.getForeignData().setCompressionType(CompressionType.PNG); File f = new File(file); byte[] fileBytes = new byte[(int) f.length()]; FileInputStream fis = new FileInputStream(f); fis.read(fileBytes); fis.close(); shape.getForeignData().setValue(fileBytes); return ms; }