Sankha Subhra Dey wrote:
I was looking for a way to add
an invisible annotation. The code I wrote isn't working, which I had
posted in my original mail. And I was looking for a way to add the
information to the Private section in a PDF file.

Every mail sent to the mailing list contains this line:
Buy the iText book: http://www.1t3xt.com/docs/book.php

If you had read chapter 15, you'd have found out there's
a method setFlags() that helps you. See attachment.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfBoolean;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.PdfWriter;

/**
 * This example was written by Bruno Lowagie. It is part of the book 'iText in
 * Action' by Manning Publications. 
 * ISBN: 1932394796
 * http://www.1t3xt.com/docs/book.php 
 * http://www.manning.com/lowagie/
 */

public class InvisibleAnnotation {

        /**
         * Creates a PDF file with annotations.
         * 
         * @param args
         *            no arguments needed here
         */
        public static void main(String[] args) {
                // step 1: creation of a document-object
                Document document = new Document();
                try {
                        // step 2:
                        PdfWriter writer = PdfWriter.getInstance(document,
                                        new 
FileOutputStream("without_annotation.pdf"));
                        // step 3:
                        document.open();
                        // step 4:
                        document.add(new Phrase("TEST"));
                } catch (Exception e) {
                        e.printStackTrace();
                }
                // step 5: we close the document
                document.close();
                
                try {
                        PdfReader reader = new 
PdfReader("without_annotation.pdf");
                        PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream("with_annotation.pdf"));
                        PdfAnnotation annotation = 
PdfAnnotation.createText(stamper.getWriter(),
                                        new Rectangle(200f, 400f, 300f, 500f), 
"Help",
                                        "This Help annotation was made with 
'createText'", false,
                                        "Help");
                        annotation.setFlags(PdfAnnotation.FLAGS_NOVIEW |
                                        PdfAnnotation.FLAGS_INVISIBLE | 
PdfAnnotation.FLAGS_HIDDEN);
                        stamper.addAnnotation(annotation, 1);
                        stamper.close();

                } catch (Exception e) {
                        e.printStackTrace();
                }

        }
}
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to