Free Support Forum -

Hyperlink to cell content

Hi support,

Please take a look on the following code and note that, at runtime, the document cannot be saved :

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();
Text text1 = new Text(sec1);
Segment segment1 = text1.getSegments().add(“link1”); //$NON-NLS-1$
segment1.setHyperLink(new HyperLinkToLocalPdf(“bmk1”)); //$NON-NLS-1$

Table table = new Table(sec1);

//add a row
Row row1 = new Row(table);

Cell cell11 = row1.getCells().add();

Text txt = new Text(cell11);
txt.getSegments().add(new Segment(txt, “A”)); //$NON-NLS-1$

Segment seg = new Segment(txt, " "); //$NON-NLS-1$
seg.setID(“bmk1”); //$NON-NLS-1$

//Segment seg1 = new Segment(txt, “B”); //$NON-NLS-1$

FileOutputStream out = new FileOutputStream(new File(“C:/Temp/HyperlinkBug.pdf”));;
catch (FileNotFoundException e)

If you delete the comments for adding the “B” segment, the document is saved.

Please advice,

Hello Milan,

I've tested the scenario and I'm able to notice that if the text segment is blank and we try to set the hyperlink to that blank segment, PDF is not generated. In your code you've created a blank segment "seg" and have assigned it an ID bmk1which is the destination for link. I'm not sure if Aspose.Pdf for Java architecture allows specifying hyperlink target to blank segments or not. I'll check it with our development team and will update you with the appropriate status.

We're sorry for your inconvenience.