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

Free Support Forum - aspose.com

Hyperlinks in vsd files

Hi Team,

I’m using Aspose Diagram for java to identify hyperlinks in a vsd file.
I was using the below code, but it is giving me incorrect data. Can you pls help me with code to identify hyperlinks in vsd files.

Attaching a sample vsd file in zip.

ActvDir.zip (128.2 KB)

Code being used.

    Diagram diag = new Diagram(dataDir+fileName1);
    int pageCount=0,shapeCount=0,hyperlinkCount=0;
    String linkName, linkURL;
    pageCount = diag.getPages().getCount();
    System.out.println("page count"+pageCount);
    System.out.println("Page Name: "+diag.getPages().getPage(0).getName());
    for(int i=0;i<pageCount;i++){
    	Page page = diag.getPages().getPage(i);
    	shapeCount=page.getShapes().getCount();
    	System.out.println("shape count" +shapeCount);
    	for(int j=1;j<=shapeCount;j++){
    		Shape shp = page.getShapes().getShape(j);
    		try{
    			hyperlinkCount = shp.getHyperlinks().getCount();
        		for(int k=0;k<hyperlinkCount;k++){
        			linkName=shp.getHyperlinks().get(k).getDescription().getValue();
        			linkURL=shp.getHyperlinks().get(k).getAddress().getValue();
        			if("".equals(linkName)){
        				linkName = linkURL;
        			}
        			
        			System.out.println(linkName+ " -  "+linkURL);
        		}
    		}catch(NullPointerException e){
    			System.out.println("No hyperlink found");
    		}
    		
       		}
    }

Thanks,
Vineet

@vineet992,

The getPage() and getShape() methods take an ID of the page and shape as a parameter and you are passing an index of the page and shape, kindly use get() method to pass indexes. There are no hyperlinks in your source Visio drawing. However, if you can find any hyperlink in the Visio drawing, then kindly share shape Id. We will investigate and share our findings with you.

@imran.rafique,

pageCount = diag.getPages().getCount();

The above code is returning result as 1, but the sample contains 2 pages.
Even if I’m trying to use diag.getPages().get(1) for 2nd page, I’m getting IndexOutOfBoundException.

The sample document doesn’t contain hyperlinks, but it will be helpful to me if you can share how to identify hyperlinks in a similar document.
I’m unable to share the exact document due to policy reasons.

Thanks.
Vineet .

@vineet992,

If the Visio drawing has two pages and the getCount() method returns the count 1, then this may a bug. We have tested your Visio drawing ActvDir.vsd and the latest version 17.8 of Aspose.Diagram for Java API returns the count 2.

You can copy and edit the original document, replicate the problem in your environment, and then share problematic Visio drawing. We will investigate and share our findings with you.

@imran.rafique

I’m getting the diag.getPages().getCount() output as 1, even after using latest version 17.8 of Aspose.Diagram.
Can you pls assist where am I going wrong.

Thanks,
Vineet.

@imran.rafique

The issue is resolved now. There was some problem with developer license.
using .get() for page and shape, resolved my issue.

Thanks,
Vineet.

@vineet992,
It is nice to hear from you that the problem has been resolved. Please feel free to reply us in case of any further assistance.