>> The annotations are in the /Annots entry of the 
page dictionary. You could try to fetch them, 
apply a transformation to the rectangle that defines 
their position, and copy them into the new document

 I am randomly using many pdfs  and so will not be sure on the exact
position of this annotations. I tried to get these annotations from the page
dictionary  and write it to the new PDf  but it fails .

My Code:
--------
PdfReader pdfReader= **
pdfWriter = PdfWriter.getInstance(pdfDocument,new
FileOutputStream("C:/final.pdf"));
pdfDocument.open();

//Lets consider pageN  = 1
pageDic = pdfReader.getPageN(pageN);
pdfWriter.addToBody(pdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)) );
=> Throws NullPointerException
 
page = pdfWriter.getImportedPage(pdfReader, pageN); image =
Image.getInstance(page); image.scalePercent(50);
image.setAbsolutePosition(0, 0); pdfDirectContent.addImage(image);

Exception Traces:
-----------------
java.lang.NullPointerException
        at 
com.itextpdf.text.pdf.PdfWriter.getNewObjectNumber(PdfWriter.java:2285)
        at
com.itextpdf.text.pdf.PRIndirectReference.toPdf(PRIndirectReference.java:84)
        at com.itextpdf.text.pdf.PdfArray.toPdf(PdfArray.java:170)
        at
com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)
        at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:396)
        at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:376)
        at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:329)
        at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:780)
        at com.hp.example.junit.Test1.setPageAttributes(Test1.java:120)
        at com.hp.example.junit.Test1.main(Test1.java:177)
Exception in thread "main" ExceptionConverter: java.io.IOException: The
document has no pages.
        at com.itextpdf.text.pdf.PdfPages.writePageTree(PdfPages.java:113)
        at com.itextpdf.text.pdf.PdfWriter.close(PdfWriter.java:1171)
        at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:780)
        at com.itextpdf.text.Document.close(Document.java:409)
        at com.hp.example.junit.Test1.close(Test1.java:165)
        at com.hp.example.junit.Test1.main(Test1.java:179)


  Please help me to define the code properly for adding these annotatoins to
the pdf.

-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Unable-to-get-text-box-using-PDF-Writer-tp2538775p2542114.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to