Hi,

I am trying to add a annotation in an existing pdfbytearray and then sending
it for download.
Here is what I am doing

try {
                        ByteArrayOutputStream pdfOut = new 
ByteArrayOutputStream();
                        InputStream pdf = new ByteArrayInputStream(pdfBytes);
                        PdfReader reader = new PdfReader(pdf);
                        com.lowagie.text.Document document = new 
com.lowagie.text.Document(
                                        reader.getPageSize(1));
                        PdfWriter writer = PdfWriter.getInstance(document, 
pdfOut);
                        int n = reader.getNumberOfPages();
                        writer.open();
                        document.open();

                        PdfImportedPage page;

                        PRAcroForm form = reader.getAcroForm();
                        if (form != null) {
                                //copy.add(reader);
                        }
//HASH MAP CONTAINS THE LIST OF ANNOTATIONS WHICH I WANT TO ADD
                        List<HashMap<Integer, Annotation>> list = new 
ArrayList<HashMap<Integer,
Annotation>>();

                        com.lowagie.text.Annotation a1;
                        

//CURRENTLY I HAVE HARD CODED THE RECTANGLE BOUNDS

                        for (int i = 1; i <= n; i++) {
                                page = writer.getImportedPage(reader, i);
                                list = getAnnotationsPerPage(annotations, 
page.getHeight(), i);
                                for (HashMap<Integer, Annotation> map : list) {
                                        for (Object key : map.keySet()) {
                                                writer.addAnnotation(
                                                                
PdfAnnotation.createText(writer,
                                                                new 
Rectangle(200, 280, 220, 300),
                                                                "Comment",
StringUtils.deleteHTMLTags(map.get(key).getDescription()), false,
"Comment"));
                                                
                                        }
                                }                               
                                Image instance = 
Image.getInstance(writer.getImportedPage(reader, i));
                                document.add(instance);
                        }
                        
                        writer.close();
                        pdfOut.flush();
                        pdfOut.close();
                        document.close();
                        return pdfOut.toByteArray();
                } catch (Exception de) {
                        de.printStackTrace();

                }



MY PROBLEM: I am able to add the annotations but a new page is also getting
added in the final PDF after the page where annotation is added also the
document size is getting messed up :|

-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/How-to-add-annotation-to-existing-document-tp2993507p2993507.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

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

Reply via email to