I am using Aspose.Diagram for Java and facing the following issue:
When adding shapes to a page, if the coordinates of the shape are outside of the page size, an additional page is not added.
I am not sure that the term ‘page’ is correct in this case, please correct me if I am wrong. What I refer to is pages that are added to the right/left up/down when adding shapes outside of the existing borders.
Note that when I manually add a shape or move a shape after it was created with Aspose.Diagram code - a page is added automatically.
Attached - a snapshot for example.
Is there anything that I can do to correct this ? Is there some kind of definitions that I should add to the diagram ?
Thank you for contacting support. In Visio, the auto size feature option of the page is available under Design tab. However, you can manually set the width and height of the page, e.g.
We have logged a feature request to automatically re-size the Visio page under ticket id DIAGRAMJAVA-50226 in our issue tracking system. Your post has also been linked to this issue. We’ll keep you informed regarding any available updates. We’re sorry for the inconvenience caused.
The page <span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:Arial;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:HE”>dimensions are changed and the rectangle is placed completely outside of the page.
I am adding two screenshots to explain what I get.
Can you please help me pigure out how to make shapes stay inside the page ?
I understand that when setting new page <span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:Arial;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:HE”>dimensions , the X and Y values are modified, so I must place my shape accordingly. In my code the shapes are placed dynamically, according to data taken from another application. So I am trying to understand how to calculate X and Y locations of shapes + keeping them all inside the page.
Thank you for being patient. Please note, if the shapes are placed outside the page, then, as a workaround, you can iterate through the shapes and extend page size according to the location of these shapes. To accomplish this task, we can compare page width and height with PinX and PinY values of the shape because PinX and PinY values present horizontal and vertical distances. PinX and PinY values are calculated from the center of the shape, so we can cover rest part by adding the half width of the shape. We can also cover drawing scale distance as narrated in the code sample below:
Use case description: A circle shape is placed outside the page towards the horizontal side. In that case, we only need to extend page width.
Sample code:
[.NET, C#]
// load source diagram
Diagram diagram = new Diagram(@“c:\temp\Drawing1.vsd”);
// get page object
Aspose.Diagram.Page page = diagram.Pages.GetPage(“Page-1”);
int shapeid = 1; // get shape
Shape shape = page.Shapes.GetShape(shapeid);
// compare page width with shape PinX value if (page.PageSheet.PageProps.PageWidth.Value < shape.XForm.PinX.Value)
{ // calculate and set page width
page.PageSheet.PageProps.PageWidth.Value = shape.XForm.PinX.Value + (shape.XForm.Width.Value / 2) + (page.PageSheet.PageProps.DrawingScale.Value / 2);
}
// save diagram diagram.Save(@“C:\temp\OutputVDX.vdx”, SaveFileFormat.VDX);
We have attached source and destination diagrams to this reply for your kind reference. We hope, this helps.
Please let us know in case of any confusion or questions.
We’re sorry for the confusion cause. In case the problem persist, then please make sure that you are using the latest version of Aspose.Diagram for Java 5.7.0. It works fine on my side.
Sample code:
[Java]
// load source diagram
Diagram diagram = new Diagram(“c:\temp\Drawing1.vsd”);
// get page object
Page page = diagram.getPages().getPage(“Page - 1”);
int shapeid = 1;
// get shape
Shape shape = page.getShapes().getShape(shapeid);
// compare page width with shape PinX value
if (page.getPageSheet().getPageProps().getPageWidth().getValue() < shape.getXForm().getPinX().getValue())
{
// calculate and set page width
page.getPageSheet().getPageProps().getPageWidth().setValue(shape.getXForm().getPinX().getValue() + (shape.getXForm().getWidth().getValue() / 2) + (page.getPageSheet().getPageProps().getDrawingScale().getValue() / 2));
}
// save diagram
diagram.save(“c:\temp\OutputVDX.vdx”, SaveFileFormat.VDX);
Thank you for the inquiry. We have attached a sample project which follows these steps:
Load a source Visio diagram.
Add a master of the shape.
Display page height and width.
Place a new shape on the page (it goes outside the Visio page).
Check if required to extend the page width.
Check if required to extend the page height.
Save Visio diagram.
We hope, this helps. In case, it does not meet with the require use case, then please provide your source diagrams, code and details. We’ll investigate and reply you appropriately.
Sure, please take your time and let us know about your precious feedback. We’ll be happy to help you in using Aspose APIs in your application projects.
Thank you for contacting support. Please note, while adding a new page you need to set all its properties, e.g. width, height, drawing scale, right page margin, etc. By default, it will have negative values. In the above case, you set the page width and height, but not drawing scale. Since its value was negative and also the calculated height of the page is negative. We have logged a feature request to fill properties automatically under ticket id DIAGRAMJAVA-50227 in our issue tracking system. As a workaround, please set all required properties and then calculate page size. Your post has also been linked to this feature. We’ll let you know once a significant progress has been made in this regard. We’re sorry for the inconvenience caused.
tamirl1:
Still having problems, now with the page height…
To place a shape out of the page height, I give a pinY value of -1 for example.
In this case - your forumula does not work.
You are right because the above sample code does not cover this scenario. We’re investigating its sample code and also in communication with our product team. We’ll get back to you soon.
Thank you for contacting support. Please use AutoFitPageToDrawingContent property of the class DiagramSaveOptions as follows:
[Java]
// load a Visio diagram
Diagram diagram = new Diagram(“c:\temp\Input.vsd”);
// use saving options
DiagramSaveOptions options = new DiagramSaveOptions(SaveFileFormat.VDX); // set Auto fit page property
options.setAutoFitPageToDrawingContent(true);
// save Visio diagram
diagram.save(“c:\temp\Output.vdx”, options);
We hope, this helps. Please let us know how it goes on your side.
Thank you for the details. We managed to replicate a use case with negative values. We have logged an improvement under ticket id DIAGRAMJAVA-50228 in our issue tracking system. Your post has also been linked to this issue. We’ll keep you informed regarding any available updates. We’re sorry for the inconvenience caused.