Pdf A Conversion hyperlink not working

Hi,
I am working with aspose java api version 21.9.
I have an index file that I create that when I convert to pdf a as bellow:
Document pdfDocument = new Document(filePath);
pdfDocument.setXrefGapsAllowed(false);
DocumentPrivilege documentPrivilege = DocumentPrivilege.getAllowAll();
PdfFileSecurity fileSecurity = new PdfFileSecurity(pdfDocument);
fileSecurity.setPrivilege(documentPrivilege);
// Convert to PDF/A compliant document
// During conversion process, the validation is also performed
pdfDocument.convert(getDataDir() + “log.xml”, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
// Save output document
pdfDocument.save(filePath);
The hyper link stop working. Only when I disable the pdf a format it starts working. I set the hyperlink as bellow:
TextFragment textFragment = new TextFragment(decodeValue(filePath));
textFragment.setHyperlink(new FileHyperlink(decodeURL1));

I attached the pdf a index file.

gtoc.zip (40.9 KB)

@operationsdotbcs

Can you please share the source PDF file so that we may try to reproduce the same on our end.

Hi,
Its not a conversion, Its a pdf I built in my program. I attached the final pdf (That is PDF A fortmat).
Same code and output without PDF A work properly.
Bellow is part of the code how I create the TOC table.

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
Page page = doc.getPages().add();
// Instantiate a table object
com.aspose.pdf.Table tab = new com.aspose.pdf.Table();

	tab.setLeft(20);
	
	
	
	// Add the table in paragraphs collection of the desired section
	page.getParagraphs().add(tab);
	// Set with column widths of the table
	
	tab.setColumnAdjustment(ColumnAdjustment.Customized );
	
	tab.setColumnWidths("40% 20% 40%");
	
	// Set default cell border using BorderInfo object
	tab.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.05F));
	// Set table border using another customized BorderInfo object
	tab.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.05F));
	
	
	
	// Create MarginInfo object and set its left, bottom, right and top margins
	com.aspose.pdf.MarginInfo margin = new com.aspose.pdf.MarginInfo();
	margin.setTop(3f);
	margin.setLeft(3f);
	margin.setRight(3f);
	margin.setBottom(3f);
	// Set the default cell padding to the MarginInfo object
	tab.setDefaultCellPadding(margin);
	tab.getMargin().setTop(30);
	
	//Create Bold table header row
	com.aspose.pdf.Row row1 = tab.getRows().add();
	TextFragment boldtext= new TextFragment("File Name");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	com.aspose.pdf.Cell cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);
	boldtext= new TextFragment("File Id");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);
	boldtext= new TextFragment("File Description");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);

@operationsdotbcs

I request you to share complete runnable code so that we can reproduce and investigate the issue.

Hi, Its a function that create a TOC pdf.

ArrayList folders = new ArrayList();
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
Page page = doc.getPages().add();
// Instantiate a table object
com.aspose.pdf.Table tab = new com.aspose.pdf.Table();

	tab.setLeft(20);
	
	
	
	// Add the table in paragraphs collection of the desired section
	page.getParagraphs().add(tab);
	// Set with column widths of the table
	
	tab.setColumnAdjustment(ColumnAdjustment.Customized );
	
	tab.setColumnWidths("40% 20% 40%");
	
	// Set default cell border using BorderInfo object
	tab.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.05F));
	// Set table border using another customized BorderInfo object
	tab.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, 0.05F));
	
	
	
	// Create MarginInfo object and set its left, bottom, right and top margins
	com.aspose.pdf.MarginInfo margin = new com.aspose.pdf.MarginInfo();
	margin.setTop(3f);
	margin.setLeft(3f);
	margin.setRight(3f);
	margin.setBottom(3f);
	// Set the default cell padding to the MarginInfo object
	tab.setDefaultCellPadding(margin);
	tab.getMargin().setTop(30);
	
	//Create Bold table header row
	com.aspose.pdf.Row row1 = tab.getRows().add();
	TextFragment boldtext= new TextFragment("File Name");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	com.aspose.pdf.Cell cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);
	boldtext= new TextFragment("File Id");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);
	boldtext= new TextFragment("File Description");
	boldtext.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
	cell2 = row1.getCells().add();
	cell2.getParagraphs().add(boldtext);
	
	
	//To repeat header in the beginning of each page
	tab.setRepeatingRowsCount(1);

for(BinderElement ele :elements) {
com.aspose.pdf.Row row2 = tab.getRows().add();
String fileName = ele.getFilePath().split("/")[ele.getFilePath().split("/").length - 1];
handleBinderElementFolderRow(ele.getFilePath(), fileName, row2, true);
handleBinderElementFileRow(ele, ele.getFilePath(), row2, false);
}

private void handleBinderElementFolderRow(String filePath, String fileName, com.aspose.pdf.Row row2, Boolean isRoot) {
if(!isRoot) {
String decodeURL1 = decodeValue(filePath.substring(0, filePath.length() - fileName.length() - 1));

	decodeURL1 = decodeURL1.replace("/", "\\");
	
	TextFragment textFragment = new TextFragment(decodeURL1);
	textFragment.setHyperlink(new FileHyperlink(decodeURL1));
	com.aspose.pdf.Cell cell2 = row2.getCells().add();
	cell2.setBackgroundColor(com.aspose.pdf.Color.getLightGray());
	cell2.getParagraphs().add(textFragment);
	//Folder Row all cells are merged
	createRowWithNoBordersWithSpan(row2);
} else {
	TextFragment textFragment = new TextFragment("Root Folder");
	com.aspose.pdf.Cell cell2 = row2.getCells().add();
	cell2.getParagraphs().add(textFragment);
	cell2.setBackgroundColor(com.aspose.pdf.Color.getLightGray());
	//Folder Row all cells are merged
	createRowWithNoBordersWithSpan(row2);
}

}

private void handleBinderElementFileRow(BinderElement ele, String filePath, com.aspose.pdf.Row row2, boolean isRelatedObject) {
com.aspose.pdf.Cell cell2 = row2.getCells().add();
String decodeURL1 = decodeValue(filePath);
TextFragment textFragment = new TextFragment(decodeValue(filePath.split("/")[filePath.split("/").length - 1]));
** textFragment.setHyperlink(new FileHyperlink(decodeURL1));**
cell2.getParagraphs().add(textFragment);
//Check if comment null, and add to cell
if(!isRelatedObject)
addBinderElementCellData(ele.getDocumentNumber(), row2);
else
row2.getCells().add();
addBinderElementCellData(ele.getComment(), row2);
}

Another note it does work with PDF A. when I create the Table with DocumentBuilder. Then the links are clickable inside PDF A.

@operationsdotbcs

A ticket with ID PDFJAVA-40957 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

1 Like