This Code is perfect. But the only problem is that I want to copy links and I want to change the property of links to inherit zoom.
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..");
}
}