I am using Pdf Writer to get the page (PdfImportedPage) and then converting
it to image for scaling. This image is finally added to the PdfContentByte.
But on this process i am missing the Pdf annotations. Please find the
attached input pdf (PdfAnnot.pdf) and generated pdf(final.pdf).

My Code:
--------
PdfReader pdfReader= **
pdfWriter = PdfWriter.getInstance(pdfDocument,new
FileOutputStream("C:/FINAL_Annot.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 let me know if we can resolve this , or if any other options are
there to get this done.

http://itext-general.2136553.n4.nabble.com/file/n2541909/final.pdf final.pdf 
http://itext-general.2136553.n4.nabble.com/file/n2541909/PdfAnnot.pdf
PdfAnnot.pdf 
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Unable-to-add-annotation-from-existing-pdf-tp2541909p2541909.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