I need to create text "Chapter1" and on click go to page 2 in AsPose PDF for Java
How can I do that in com.aspose.pdf (not legacy)?
Is it supported? Examples?
Hi Alex,
//open
document<o:p></o:p>
Document document = new Document("c:/pdftest/facture.pdf");
//create link
Page page = document.getPages().get_Item(1);
LinkAnnotation link = new LinkAnnotation(page, new com.aspose.pdf.Rectangle(100, 100, 150, 150));
// link for second page of PDF
link.setDestination(new com.aspose.pdf.XYZExplicitDestination(2, 100, 100, 1));
page.getAnnotations().add(link);
//save updated document
document.save("c:/pdftest/PDFWithHyperlink+output.pdf");
Is it possible to do it without rectangles and XYZ coordinates. I only need a simple text(!!!) element on the page to be clickable. Legacy classes provide very good examples. I do not need to create any annotations or rectangles, just table on contents. When a person clicks on table of contents element “Chapter 2 …10” I would like to go to page 10.
Hi Alex,
com.aspose.pdf.facades.PdfContentEditor
editor = new com.aspose.pdf.facades.PdfContentEditor();<o:p></o:p>
// open source PDF file
editor.bindPdf("c:/pdftest/Doc+3.pdf");
java.awt.Rectangle rect=new java.awt.Rectangle(50,50, 200, 200);
java.awt.Color clr=new java.awt.Color(255,255,255);
// create link towards second page of PDF file
editor.createLocalLink(rect, 2, 1, clr);
editor.save("c:/pdftest/LocalinkTest.pdf");
Hi Alex,
the sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34197. We will
investigate this issue in details and will keep you updated on the status of a
correction. We are sorry for this inconvenience.
<o:p></o:p>
//
Load an existing PDF files<o:p></o:p>
com.aspose.pdf.Document doc = new com.aspose.pdf.Document("c:/pdftest/emd-2012-014876.pdf");
// Get access to first page of PDF file
com.aspose.pdf.Page tocPage = doc.getPages().insert(1);
// Create object to represent TOC information
com.aspose.pdf.TocInfo tocInfo = new com.aspose.pdf.TocInfo();
com.aspose.pdf.TextFragment title = new com.aspose.pdf.TextFragment("Table Of Contents");
title.getTextState().setFontSize(20);
title.getTextState().setFontSize(com.aspose.pdf.FontStyles.Bold);
// Set the title for TOC
tocInfo.setTitle(title);
tocPage.setTocInfo(tocInfo);
// Create string objects which will be used as TOC elements
String[] titles = new String[4];
titles[0] = "First page";
titles[1] = "Second page";
titles[2] = "Third page";
titles[3] = "Fourth page";
for (int i = 0; i < 4; i++)
{
// Create Heading object
com.aspose.pdf.Heading heading2 = new com.aspose.pdf.Heading(1);
com.aspose.pdf.TextSegment segment2 = new com.aspose.pdf.TextSegment();
heading2.setTocPage(tocPage);
heading2.getSegments().add(segment2);
// Specify the destination page for heading object
heading2.setDestinationPage(doc.getPages().get_Item(i + 2));
// Destination page
heading2.setTop(doc.getPages().get_Item(i + 2).getRect().getHeight());
// Destination coordinate
segment2.setText(titles[i]);
// Add heading to page containing TOC
tocPage.getParagraphs().add(heading2);
}
// Save the updated document
doc.save("c:/pdftest/TOC_Output_Java.pdf");
The issues you have found earlier (filed as PDFNEWJAVA-34197) have been fixed in Aspose.Pdf for Java 10.0.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(2)