Free Support Forum -

Align textblock in Shape

I use Aspose.Diagram for Java to create a VISIO diagram from a SVG document.

How can I align textblock to top in the Diagram Shape. By default it is centered and it is possible to align only a “text in textblock”. Maybe I can change a size of a textblock to be the same as its Shape size and “text in textblock” alignment will be enough for this?

Didn’t find any working example in the forum or API reference.


The TextXForm class helps to set the position of text inside the shape in the same way as we can set Text Block Format section in the shapesheet with Microsoft Visio application. Please refer to this help topic: Format Text in the Visio Shape’s Text Block Section

Thanks for reply, using help topic reference (align text to the left section) didn’t help. All letters are aligned to left and looking weird (see attached VISIO - (11.9 KB)

The code used for that shapes is here and text alignment is in the end of the createVisio() method:

public Object createVisio(IFDVisioContext ctx) throws Exception {
    AffineTransform tr = ctx.getParentTransform();
    AffineTransform nt = new AffineTransform();
    double xCentr = (getPosition().getX() + getRectangle().getCenterX());
    double yCentr = (getPosition().getY() + getRectangle().getCenterY());
    nt.translate(xCentr, -yCentr);
    double translateX = nt.getTranslateX();
    double translateY = nt.getTranslateY();
    long shapeId = ctx.getDiagram().addShape(translateX, translateY, ctx.getMasterNodeName(), ctx.getCurrentPage().getID());
    Shape legendItemShape = ctx.getDiagram().getPages().getPage(ctx.getCurrentPage().getID()).getShapes().getShape(shapeId);
    legendItemShape.setWidth(getRectangle().getWidth() / IteraplanVisioUtils.VISIO_SCALE);
    legendItemShape.setHeight(getRectangle().getHeight() / IteraplanVisioUtils.VISIO_SCALE);
    // Borders
    if (getBorderLinePattern() != null) {
    } else {
      // No border
    // Legend item text
    if (!getName().isEmpty() && getName() != null) {
      // Text value
      legendItemShape.getText().getValue().add(new Txt(getName()));
      // Font size
      legendItemShape.getChars().add(new Char());
      legendItemShape.getChars().get(0).getSize().setValue(getIsTitle() ? 0.17 : 0.13);
      // Legend item text color
      StyleSheet textStyle = new StyleSheet();
      // Align text to left (as in Aspose tutorial)
      double angleDeg = 0;
      double angleRad = (Math.PI / 180) * angleDeg;
    } else {
    // Legend item color
    String[] colors = getColor().split(";");
    // Single value coloring

    return legendItemShape;


Please send us your source Visio drawing and the fully compilable code, because there are unknown objects in your source code. We will investigate your scenario in our environment, and share our findings with you.

@imran.rafique, sorry, but not fully understand what do you mean under “source Visio drawing”? Is it a document used for Diagram diagram = new Diagram(dataDir + fileName);, master .vssx or an output after

Simplified code to a function working with shape text:

// Text is set to rectangular shape
  private void setShapeText(Shape shape) {
    // Text value
    shape.getText().getValue().add(new Txt("Hello world"));
    // Font size
    shape.getChars().add(new Char());
    // Text color
    StyleSheet textStyle = new StyleSheet();
    textStyle.getFill().setFillForegnd(new ColorValue("#aaaaaa", MeasureConst.COLOR));
    // Align text to left (as in Aspose tutorial)
    double angleDeg = 0;
    double angleRad = (Math.PI / 180) * angleDeg;

Thanks for replying!


Please send us the input Visio drawing and stencil file (if any VSS or VSSX).
Diagram diagram = new Diagram(dataDir + fileName);

I use this stencil file: (12.0 KB). As an input Visio file I use temporarily created .vsdx: (8.9 KB)


We are unable to replicate the problem of misaligned text in our environment as we could view in your output drawing (iteraplan-InformationFlowDiagram-2018-06-20__15_33_16.vsdx). Please send us the complete code, so that we could replicate the same problem in our environment and also let us know the version of Aspose.Diagram for Java API. Your response is awaited.

@imran.rafique, attached complete sandbox project where the problem is replicated: (200.2 KB). I use Aspose Diagram 18.3.

! Please, include your “Aspose.Diagram.lic” file to the DIR “/src/main/resources/templ” to build and run the project.
! Run to get the resulting .vsdx file (it will be added to the root directory, file name - ifd1.vsdx)

Currenly there is ifd1.vsdx in zipped sandbox folder, which represents the problem: text in red shapes looks strange, but should be aligned to left and be readable.

Waiting for your results, thank you!


We have tested your application project in our environment, and it shows a null pointer error on loading an SVG into the Document instance before the call of Aspose.Diagram API.

Document document = factory.createDocument("svg", svgAsStream);

Please review and let us know in case ambiguity or queries.

@imran.rafique, after zipping a project, tool created additional “Sandbox” folder. Skip it and open inner one, so app will use correct directories. Thanks!


We have investigated your scenario, and could find that the SVG file is available on the specified path. The input stream instance is also not null. Please take a look over this snapshot:

@imran.rafique, thanks for investigation. It is normal for getXMLParserClassName() to return null, the default parser is the JRE included parser then.

You can just skip this, resuming Runner.main() and review the resulting VISIO document. Also forgot to guide you to, where text is set and aligned to the shape.


When we skip the call of getXMLParserClassName() method, the compilation errors are being generated for other lines of code. Please simplify the code, and elaborate a bit more about the usage of file.

@imran.rafique, attaching working version (190.4 KB)
If still produces some errors, please send detailed error description or screenshot.

More deeply about how everything works:
After reading SVG content and minor preprocessesisng (replacing fill=“transparent”) it is saved to a document (, line 27).
Then SVG document is transcoded to context object with hierarchy (, line 28).
That context wiil be used in when calling buildVisioDiagram() to build Visio items for all elements of SVG document.
Pay attention on creation of Node object (, line 131) and also for building its Visio shape with text (, line 51). There setShapeText() method is used for text alignment.


We are unable to run your application project in our environment. There are object reference errors, please send us a ZIP of all Jar files and simplify the code.

@imran.rafique, please, provide full description of errors, because everything is running on my environments, both Eclipse and IDEA.


We have tried to Build shared SandBox project in NetBeans but the Build fails because declared dependencies under Dependencies folder are not downloaded fine; consequently, further errors occur while parsing Java classes in different packages including the Java classes under com.edvantis.iteraplan and other folders. Therefore, please share the JAR files for declared dependencies and also remove unnecessary classes to narrow down the problem so that we may proceed further to address your concerns efficiently.

@Farhan.Raza, thank you for clarification. Have opened my project in NetBeans and reproduced the issue you have mentioned before. Have fixed this by setting correct jre version. Also all JARs are included in target/lib.

Please, import the project to your NetBeans instance and try running it again:

Select as main class and also don’t forget to attach your Aspose.Diagram.lic file to \src\main\resources\templ. Resulting drawing will be added to the project root.


Thank you for updating the data.

We are investigating the scenario in our environment and will get back to you with our findings soon.