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

Free Support Forum - aspose.com

Set local Hyperlink in table

Hi,
we want to add a LocalHyperlink to a TextFragment in a
TableCell. We tried it with the following code, but it seems that the link just
direct to the page the table is on, not on the configured page.

Is there another way to do this?


Table table = new Table();

Row r = table.getRows().add();

Cell cell = new Cell();

TextFragment fragment = new TextFragment(“Some text”);

LocalHyperlink l = new LocalHyperlink();
l.setTargetPageNumber(2);
fragment.setHyperlink(l);

cell.getParagraphs().add(fragment);

r.getCells().add(cell);



Thanks,Ina

Hello Ina,


Thanks for using our API’s.

I have tested your code and it works fine with a valid license on my end. I have attached the generated output PDF document having local hyperlink to a TextFragment in a TableCell as of your code. For your reference I am adding full sample code which I used to generate output file.

// Load source PDF document
Document doc = new Document(“C:/inputdocument.pdf”);
// Initializes a new instance of the Table
Table table = new Table();
Row r = table.getRows().add();
Cell cell = new Cell();
TextFragment fragment = new TextFragment("#2");
LocalHyperlink l = new LocalHyperlink();
l.setTargetPageNumber(2);
fragment.setHyperlink(l);
cell.getParagraphs().add(fragment);
r.getCells().add(cell);
// Add table object to first page of input document
doc.getPages().get_Item(1).getParagraphs().add(table);
// Save updated document containing table object
doc.save(“C:/document_with_table.pdf”);

If you still face any issue, please feel free to contact us.

Best Regards,

Hello Fahad,
thanks for your answer. I tested your code and its working.
The problem I had was, that I tried to set the hyperlink to a page
before the page with the table, which is still a problem.

It seems as the page count for the links starts with the page the table is on.

Best regards,
Ina

Hello Ina,


We are sorry for the inconvenience.

I will appreciate, if you please share your sample code along with the input PDF file. It will help us to understand your requirement exactly and address it accordingly.

Best Regards,
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}