iTextPDF 7 - Table of content with clickable page numbers - java

I'm trying to create a table of content with iTextPDF 7 in Java from existing PDFs.
I've tried to use Link link = new Link() and PdfAction.createGoTo(PdfExplicitDestination.createFit(pageNum)) but to no avail.
I can't link the page number/row in TOC to the respective page in the end PDF (after merging).
The documentation on their website only gets me so far and I'm out of ideas.
What is the correct way to create a TOC for existing PDFs and how to implement it correctly?

Related

Navigate to page when page number is clicked in table of contents of a pdf generated using itext

I'm using IText to generate a pdf for my project. Using help from this
How to generate a Table of Contents "TOC" with iText?, I was able to generate a pdf with TOC. However I'm unable to figure out how can I navigate to a page when page number is clicked. I tried adding action inside the pdf template but that doesn't seem to work. Thanks in advance for your help.
This is what I've added to the answer already given in the linked question:
final PdfTemplate template2 = this.tocPlaceholder.get("Test");
template2.beginText();
template2.setFontAndSize(baseFont, 12);
template2.setTextMatrix(50 - this.baseFont.getWidthPoint(String.valueOf(writer.getPageNumber()), 12), 0);
template2.showText(String.valueOf(writer.getPageNumber()));
PdfAction action = PdfAction.gotoLocalPage(writer.getPageNumber(),new PdfDestination(0),writer);
template2.setAction(action , 0,0,0,0);
template2.endText();

How to set hidden element/text/id in background for visible text in pdf document

I am giving internal link in pdf document using pdfbox library. For that I am comparing the string and get the co-ordinates of string from pdf document and add link on string. This is working fine and here is the link.
Now, I have two same string and I want to redirect to two different pages like following
Link 1 -> redirects to Page 3
Link 1 -> redirects to Page 5
Is there any way that while creating pdf I add some hidden element/text/id in Link 1 in background from which I can identify on which page I should redirect.

Setting footer in first page of a pdf file using dynamic reports

I am using java 8 and dynamic reports 6.0.0. I am generating a pdf file. I have to set the footer only in the first page.
There is a default method for setting the footer only in last page named lastPageFooter().
Code for adding footer in last page :
JasperReportBuilder report = new JasperReportBuilder();
report.lastPageFooter(cmp.text("footer text"));
Similarly I want to apply footer only for the first page. Please let me know how it can be one. Thanks in advance.

PDF is getting change after loading using PDFBOX jar

I have a PDF having first page as different page ( as we have in MS word functionality under "Design" tab ). and the same PDF is passed to PDFBOX using below code :
File originalPdfFile = new File("D:\\AsposeOutput_temp.pdf");
PDDocument originalDocument = PDDocument.load(originalPdfFile);
originalDocument.save("D:\\pdfBoxGen.pdf");
But when i am opening the PDF that is generated by PDFBOX, is modified. I have attached the input PDF (named AsposeOutput_temp.pdf) and output PDF (named : pdfBoxGen.pdf). I want the PDF to same as i am passing as input.
File links : https://gofile.io/?c=lLPpQz
Any help would be greatly appreciated!!
I got the solution for the above problem. There was no issue with PDFBOX library. it was with the Aspose word.The input file that was passed to PDFBOX library , was having section break internally and the same was making the improper alignment of footer.

Adding table to existing PDF on the same page with tagging - ITEXT

this question is continuation of the link
Adding table to existing PDF on the same page - ITEXT
this link proved the way to create table in existing PDf , but the issue is the generated table are not " tagged " .

Categories

Resources