import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList;
import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfAction; import com.itextpdf.text.pdf.PdfArray; import com.itextpdf.text.pdf.PdfCopy; import com.itextpdf.text.pdf.PdfDestination; import com.itextpdf.text.pdf.PdfDictionary; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfObject; import com.itextpdf.text.pdf.PdfReader; public class links { public static void main(String[] args) throws DocumentException, IOException,FileNotFoundException { String src = "E:/bookmark.pdf"; String destination = "E:/links.pdf"; PdfReader reader=new PdfReader(src); reader.consolidateNamedDestinations(); Document doc=new Document(); PdfCopy pdfCopy = new PdfCopy(doc,new FileOutputStream(destination)); doc.open(); int n = reader.getNumberOfPages(); PdfDestination d = new PdfDestination(PdfDestination.XYZ,-1,-1,0.0F) ; PdfAction act = PdfAction.gotoLocalPage(1, d, pdfCopy); for (int i=1; i <= n ;i++) { PdfDictionary pageDic = reader.getPageN(i); PdfArray arrayann = pageDic.getAsArray(PdfName.ANNOTS); if (arrayann != null) { //reader.addPdfObject(pageDic.get(PdfName.ANNOTS)); PdfArray annot=(PdfArray)PdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)); ArrayList<PdfObject> arrAnnot = new ArrayList<PdfObject>(); arrAnnot = annot.getArrayList(); for (int j = 0; j < arrAnnot.size(); j++) { PdfDictionary annots = (PdfDictionary)PdfReader.getPdfObject(arrAnnot.get(j)); if (PdfName.LINK.equals(annots.get(PdfName.SUBTYPE))) { annots.remove(PdfName.DEST); annots.put(PdfName.DEST,act); } } } pdfCopy.addPage(pdfCopy.getImportedPage(reader, i)); pdfCopy.freeReader(reader); } reader.close(); pdfCopy.close(); doc.close(); System.out.println("The Pdf is Created.."); } } This code works fine. all links properties to inherit zoom in existing document. but there is one problem that the links containing pages or their destination change to local page. i want to change the property only. link destination page numbers remain same as existing document only. is it possible in itext. anyone -- View this message in context: http://itext-general.2136553.n4.nabble.com/I-Want-to-Change-all-the-Links-Destination-of-Existing-Pdf-to-PdfDestination-XYZ-1-1-0-0F-tp4659908p4659909.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php