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

Free Support Forum - aspose.com

Getting page object using Index

Hello


Iam using Aspose Diagram for java 5.7.0 with Aspose Total License.

Is there any way to extract page from visio diagram using Page Index.

Example :
If I have 7 pages within my visio document each have index 0,1–upto 6 same as in Array.
Is there any way to get pages directly based on their indices.
As currently through the documentation I could find 2 methods :


Regards
Shubhi

Hi Shubhi,


Thank you for contacting support. Yes, the version 5.7.0 has support of getting a page object by its index. Please use these lines of code:

[Java]
// Call the diagram constructor to load diagram from a VDX file
Diagram diagram = new Diagram(“Drawing1.vdx”);

// Set page index
int pageid = 2;
// Get page object by index
Page page2 = diagram.getPages().get(pageid);

Hello


Page index is being set randomly.

Kindly find the example i am trying it is giving me null pointer exception As Page Id’s that are being assigned to pages within Visio Diagram not in sequence .

PFA Source Code file :AsposeVdxIssue.java
Input Diagram MeetRoom_AddedPAge.vsd

Regards
Shubhi

Hi Shubhi,

Thank you for supplying source diagram and code. The null reference error occurred because the code is passing page id 1 to the getPage method and there is no available page with id 1 in the Visio diagram. Please use “get” instead of the “getPage” method. Please check this modified code:

[Java]

Diagram diagram = new Diagram(“c:\temp\MeetRoom_AddedPAge.vsd”);

// Set page index
for(Page page:(Iterable)diagram.getPages())
{
System.out.println(page.getID());
}

for(int i=0;i<diagram.getPages().getCount();i++)
{
[//System.out.println](https://system.out.println/)(diagram.getPages().getPage(i).getName());
System.out.println(diagram.getPages().get(i).getName());
}