We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pages not added automatically

Hello,


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 ?

Thanks in advance !
Tamir.

Hi Tamir,


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.

diagram.Pages[0].PageSheet.PageProps.PageHeight.Value = 8;
diagram.Pages[0].PageSheet.PageProps.PageWidth.Value = 11;


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.

Thanks for you quick answer Imran !


I do have the “Auto Size” option active in my Visio definitions. Still, it does not work when creating the diagram from Aspose.

I will use the manual resize meanwhile.

Thanks,
Tamir.

Hi again,


I still need some help with this, I am having problems with resizing the page.

If I don’t resize the page and add a rectangle with x = 1, y = 10.5.
Like this:
page.addShape(1, 10.5, 1, 1, rectangleMaster);

The rectangle is placed at the top left of the diagram.

If I add the lines:
page.getPageSheet().getPageProps().getPageHeight().setValue(4);
page.getPageSheet().getPageProps().getPageWidth().setValue(5);

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.
Thanks in advance !
Tamir.

Hi Tamir,


Thank you for the inquiry. We’re working over query and will get back to you soon.

Hi Tamir,


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.


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,


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);

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,


Thank you for the inquiry. We have attached a sample project which follows these steps:

  1. Load a source Visio diagram.
  2. Add a master of the shape.
  3. Display page height and width.
  4. Place a new shape on the page (it goes outside the Visio page).
  5. Check if required to extend the page width.
  6. Check if required to extend the page height.
  7. 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.

Thank you very much Imran !

I will look into your example and will let you know if I need any more help.

Hi Tamir,


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.

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,


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.

In addition, I would really appreciate a sulotion that will add pages automatically.
I belive that this is a critical bug and should be solved ASAP.
Working around this bug has already cost me a lot of time.

Thanks in advance !
Tamir.

Hi Tamir,


Thank you for the inquiry. We’re working over your query and will get back to you soon.

Hi Tamir,


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.

Thanks for your answers Imran !

I’ll wait to hear from you.

Hi Tamir,


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.

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,


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.