Flatten() disables/removes clickable links within pdf

Hi,

after flattenning pdf the links within document like TOC table stop working.
This is reproducible at least on aspose-pdf lib v 18.1 and 18.5

Sample code:
public class PdfClickableTOC {
private static final String SRC_DOC_PATH = “d:\temp\sampledocs\clickable toc\clickable_toc.pdf”;

	public static void main(String[] args) {
		try {			
			try (
					InputStream is1 = new FileInputStream(SRC_DOC_PATH);
					OutputStream os = new FileOutputStream("d:\\temp\\sampledocs\\clickable toc\\out-no flatten.pdf");
			) {							
				Document doc = new Document(is1);				
				doc.save(os);
			}

			try (
					InputStream is1 = new FileInputStream(SRC_DOC_PATH);
					OutputStream os = new FileOutputStream("d:\\temp\\sampledocs\\clickable toc\\out-flatten.pdf");
			) {							
				Document doc = new Document(is1);				
				doc.flatten();
				doc.save(os);
			}

			try (
					InputStream is1 = new FileInputStream(SRC_DOC_PATH);
					OutputStream os = new FileOutputStream("d:\\temp\\sampledocs\\clickable toc\\out-flatten-settings.pdf");
			) {							
				Document doc = new Document(is1);
				
				FlattenSettings settings = new FlattenSettings();
				settings.setUpdateAppearances(true);
				settings.setCallEvents(true);				
				doc.flatten(settings);
				doc.save(os);
			}

			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}

clickable_toc.pdf (38.8 KB)

@konopka

Thank you for contacting support.

We have been able to reproduce the scenario in our environment. An investigation ticket with ID PDFJAVA-37824 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

@konopka

Regarding PDFJAVA-37824, this is expected behavior of API. Flattening applies to all fields including annotations. It removes all fields from the document and places their values instead. Interactive links of TOC are also annotations with type i.e. LinkAnnotation and has no appearance but applied to the specific page region. The ticket is closed now. In case of any further inquiry, please feel free to ask.