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

Free Support Forum - aspose.com

Action is Null for the LinkAnnotations in PDF document which was converted from Word

Hi,
We have a word document with TOC & converted it to PDF, when tested with acrobat links are working fine and on edit of hyperlink actions are displayed in acrobat DC.
but when we tested from the code. Actions are coming null.

I have attached my source code

for(int i=1; i <= pdfDocument.getPages().size(); i++) {
for (Annotation linkAnnot : (Iterable) pdfDocument.getPages().get_Item(i).getAnnotations()) {
Page currentPage = pdfDocument.getPages().get_Item(i);
if(linkAnnot.getClass().equals(LinkAnnotation.class)) {
LinkAnnotation linkAnnotation = (LinkAnnotation) linkAnnot;
if(null != linkAnnotation.getAction()) {

					} else {
						**// getting action Null**
					}
				}
			}
		}

@rampujar

Can you please share your sample file(s) for our reference? We will test the scenario in our environment and address it accordingly.

Hi Asad,
Yes I have attached the sample document.
sample_doc_for_testing_1.pdf (105.9 KB)

Thanks and Regards,
Sriram

@rampujar

We were able to notice the similar issue in our environment while testing the scenario with Aspose.PDF for Java 21.3. Therefore, have logged it as PDFJAVA-40388 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@rampujar

We would like to share with you that we have investigated the earlier logged ticket and found that the TOC can use not only Actions but destination object.

Please use the following code to get appointments:

        Document pdfDocument = new Document(dataDir + "sample_doc_for_testing_1.pdf");
        for(int i=1; i <= pdfDocument.getPages().size(); i++) {
            for (com.aspose.pdf.Annotation linkAnnot : pdfDocument.getPages().get_Item(i).getAnnotations()) {
                Page currentPage = pdfDocument.getPages().get_Item(i);
                if(linkAnnot.getClass().equals(LinkAnnotation.class)) {
                    LinkAnnotation linkAnnotation = (LinkAnnotation) linkAnnot;
                    if(null != linkAnnotation.getAction()) {
                        System.out.println("Action is there");
                    } else {
                        System.out.println("Action is null");
                        if(null != linkAnnotation.getDestination()) {
                            System.out.println("Destination is there");

                            IAppointment dest = linkAnnotation.getDestination();
                            System.out.println(dest.toString());
                            if(dest instanceof XYZExplicitDestination){
                                XYZExplicitDestination xyzDest = (XYZExplicitDestination)dest;
                                System.out.println("Destination page number: "+ xyzDest.getPageNumber());
                                System.out.println("Destination x: "+ xyzDest.getLeft());
                                System.out.println("Destination y: "+ xyzDest.getTop());
                                System.out.println("Destination zoom: "+ xyzDest.getZoom());
                            }

                        } else {
                            System.out.println("Destination is null");

                        }
                    }
                }
            }
        }