Hi,
I want to read all the named destination from a pdf document, also I want to read a particular Named destination from a pdf document. I searched in aspose documentation. I didnt find the code where i could achieve this. Please help me out with this.
Thanks,
Sriram Pujar
@rampujar
Would you kindly share a sample PDF document for our reference. We will test the scenario in our environment and address it accordingly.
Hi Asad,
Yes FYA
tenant_setup_tenant.pdf (34.5 KB)
tenant_setup_tenant_invalid.pdf (16.0 KB)
-
tenant_setup_tenant.pdf contains valid bookmarks/ hyperlinks ,named destination
-
tenant_setup_tenant_invalid.pdf contains invalid bookmarks/hyperlinks, named destination
@rampujar
Please check following code snippet in order to get named destinations from PDF document and share your feedback with us if you have other different requirements:
Get Named Destinations from PDF document
Document doc = new Document(dataDir + "tenant_setup_tenant.pdf");
DestinationCollection dest = doc.Destinations;
Dictionary<string, int> Result = new Dictionary<string, int>();
for (int index = 0; index < dest.Count; index++)
{
KeyValuePair<string, object> asdf = (KeyValuePair<string, object>)dest[index];
int aspage = dest.GetPageNumber(asdf.Key, true);
Result.Add(asdf.Key, aspage);
}
Furthermore, you can also read particular named destination using following code:
Get Particular Named Destination
string destinationName = "dest1";
Document doc = new Document("src.pdf");
if (doc.NamedDestinations[destinationName] !=null)
Console.WriteLine("Destination exists");
else
Console.WriteLine("Destination doe not exist");
Hi Asad,
I tried the following code. I am getting java.lang.NoClassDefFoundError: com/aspose/pdf/nameddestinations/NamedDestinationCollection. I am using apose 19.2.pdf version
@rampujar
The above code snippet was in C#.NET. However, in case you are using it in Java, would you kindly share the complete code snippet and JDK version in which you are testing it.
Hi Asad,
here is the code I I had written in Java :
com.aspose.pdf.Document pdfDocument = null;
NamedDestinationCollection namedDestinations = pdfDocument.getNamedDestinations();
if(null != namedDestinations.get_Item(“some named destinaion”)) {
ExplicitDestination exp = (ExplicitDestination) namedDestinations.get_Item(named.getName());
pageNum = exp.getPageNumber();
if(pageNum == 0) {
List namedDestinBk = (List) objMap.get(BoConstants.PDF_NAMED_BK);
namedDestinBk.add(LocalizedTextHelper.getText(“ls-pub-validation-295”, new Object[] { childOutlineItem.getTitle() }).concat("\n"));
}
} else {
List namedDestinBk = (List) objMap.get(BoConstants.PDF_NAMED_BK);
namedDestinBk.add(LocalizedTextHelper.getText(“ls-pub-validation-295”, new Object[] { childOutlineItem.getTitle() }).concat("\n"));
}
I am using jdk1.8.0_171 veersion
Thanks,
Ram Pujar
@rampujar
Would you kindly try calling NamedDestinationCollection as follows:
com.aspose.pdf.nameddestinations.NamedDestinationCollection namedDestinations = pdfDocument.getNamedDestinations();
Also, try using Aspose.PDF for Java 19.12. In case you still face any issue, please feel free to let us know.