Hello,
Hi Tamir,
Thanks for you quick answer Imran !
Hi again,
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.
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.
Hi Tamir,
Hi Tamir,
// get page object
Aspose.Diagram.Page page = diagram.Pages.GetPage(“Page-1”);
int shapeid = 1;
// get shape
Shape shape = page.Shapes.GetShape(shapeid);
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.
Hi Imran,
Thank you for your answer.
I have tried implementing your suggestion, but it is not working for me.
I am working in Java environment, I converted the code sample you gave to Java – but I am not sure I did it correctly.
I will appreciate an example in Java, it will also help if you can attach the full source code.
Thanks,
Tamir.
Hi Tamir,
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);
Hi Imran,
My apologies, I am still having problems with this issue.
I will really appreciate it, if you will attach the full Java code of your program.
The example you added, does not contain the part of adding the shape, also I don't know if you defined any default width and height to the page.
It will help me to debug your code, so I can understand what is wrong with my code.
With thanks,
Tamir.
Hi Tamir,
- 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.
Thank you very much Imran !
Hi Tamir,
Hi Imran,
After some more investigation of the issue, I found the cause of the problems I had.
I was trying to do the following:
- - Clear all the pages from the diagram.
- - Add a new page to the diagram.
- - Add the shapes on the new page.
When doing this, the dimensions of the page were:
Width :-1.7976931348623157E308
Height :-1.7976931348623157E308
And when trying to resize the page as you suggested, it had bad results.
Even when I tried to set the dimensions of the page – it did not help.
At the moment I can work with just one page and avoid doing this, but I will appreciate it if you will examine this problem.
I am attaching an example – based on your source code and adding my code.
Thanks !
Tamir.
Hi Again,
Hi Tamir,
Hi Tamir,
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.
Thanks for your answers Imran !
Hi Tamir,
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);
Thanks again Imran !
I tested the save option as you suggested – it works, but only partially.
When using positive X and Y values it works good. Example:
page.addShape(30, 30, 1, 1, "Circle");
But when using negative values, the page is not resized. The shape is placed out of the page bounderies. Example:
page.addShape(-1, -1, 1, 1, "Circle");
Hi Tamir,