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

Free Support Forum - aspose.com

Aspose.PDF created Internal Link not working in "Saved As" Pdf via Acrobat reader

Hi Team,

We are creating Internal Links (Links which point to a different page within same PDF file) using ASPOSE pdf.19.1

  • The attached input file (Links.pdf) has one existing Internal link in text [ExistingInternalLink]- pointing to page 2.
  • We are creating another Internal Link using ASPOSE pdf in text [InternalLink]- should point to page 2.
    On executing below code, the link successfully gets created on the text [InternalLink] and points to page 2.

Next, if we do SAVE AS using “Adobe Acrobat Reader” and make a new pdf file LinksAFTERACROBATSAVEAS.pdf

ACTIONS property gets deleted for the Internal Link created by ASPOSE pdf

Hence for below terms:

  • [ExistingInternalLink] – Link persists and points to page 2.
  • [InternalLink] – Link persists but with no ACTIONS property. So the link no longer points to page 2. This is the issue we are facing for all links in our system.

PFB code snippet. Attached document which we are using for testing.

//Code snippet for Creating Internal Link
String filename=“C:\Users\Guest\Desktop\Links.pdf”;
Document document = new Document(filename);
Page page = document.getPages().get_Item(1);
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[InternalLink]");
page.accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
for(TextFragment textFragment:textFragmentCollection) {
Rectangle rectangle=textFragment.getRectangle();
XYZExplicitDestination destination = new XYZExplicitDestination(2, 0, 820, 0);
LinkAnnotation linkAnnotation = new LinkAnnotation(page, rectangle);
linkAnnotation.setDestination(destination);
Border border = new Border(linkAnnotation);
linkAnnotation.setBorder(border);
linkAnnotation.getBorder().setWidth(1);
page.getAnnotations().add(linkAnnotation);
}
document.save();
document.close();
document.dispose();
System.out.println(“internal link processing completed”);

However, we are not facing any issue with External Links(links which point to different PDF). Only Internal Links creating the problem. Please find code snippet used for testing External link.
//Code snippet for Creating External Link
document = new Document(filename);
page = document.getPages().get_Item(1);
textFragmentAbsorber = new TextFragmentAbsorber("[ExternalLink]");
page.accept(textFragmentAbsorber);
textFragmentCollection = textFragmentAbsorber.getTextFragments();
for(TextFragment textFragment:textFragmentCollection) {
Rectangle rectangle=textFragment.getRectangle();
XYZExplicitDestination destination = new XYZExplicitDestination(2, 0, 820, 0);
LinkAnnotation linkAnnotation = new LinkAnnotation(page, rectangle);
linkAnnotation.setAction(new GoToRemoteAction(“dummyfile.pdf”, 1));
Border border = new Border(linkAnnotation);
linkAnnotation.setBorder(border);
linkAnnotation.getBorder().setWidth(1);
page.getAnnotations().add(linkAnnotation);
}
document.save();
document.close();
document.dispose();
Links.pdf (25.2 KB)
dummyfile.pdf (4.8 KB)
LinksAFTERACROBATSAVEAS.pdf (24.0 KB)

@sachinkumardev

We were able to replicate the issue in our environment with Aspose.PDF for Java 20.6 and logged it as PDFJAVA-39572 in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.