1 - Only by creating a new document using the pages of the original one.

2 - This code will work:

import java.io.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.util.ArrayList;
import java.util.HashMap;

public class ListNotes extends java.lang.Object {
    
    public static void print(String value) {
        byte b[] = PdfEncodings.convertToBytes(value, null);
        if (b.length >= 2 && b[0] == (byte)254 && b[1] == (byte)255)
            value = PdfEncodings.convertToString(b, PdfObject.TEXT_UNICODE);
        else
            value = PdfEncodings.convertToString(b, PdfObject.ENCODING);
        System.out.println(value);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        if (args.length < 1) {
            System.err.println("usage: java ListFields file");
            return;
        }
        try {
            PdfReader reader = new PdfReader(args[0]);
            for (int page = 1; page <= reader.getNumberOfPages(); ++page) {
                PdfDictionary dPage = reader.getPageN(page);
                PdfArray annots =
(PdfArray)reader.getPdfObject((PdfObject)dPage.get(PdfName.ANNOTS));
                if (annots == null)
                    continue;
                ArrayList ali = annots.getArrayList();
                for (int annot = 0; annot < ali.size(); ++annot) {
                    PdfObject refObj = (PdfObject)ali.get(annot);
                    PdfDictionary an =
(PdfDictionary)reader.getPdfObject(refObj);
                    PdfName name = (PdfName)an.get(PdfName.SUBTYPE);
                    if (name == null || !name.equals(PdfName.TEXT))
                        continue;
                    PdfArray rect = (PdfArray)an.get(PdfName.RECT); //this
is the position
                    PdfString tx = (PdfString)an.get(PdfName.T);
                    if (tx != null)
                        print(tx.toString());
                    tx = (PdfString)an.get(PdfName.CONTENTS);
                    if (tx != null)
                        print(tx.toString());
                    System.out.println();
                }
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Best Regards,
Paulo Soares

> -----Original Message-----
> From: rajesh  r [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, February 18, 2003 4:26
> To:   [EMAIL PROTECTED]
> Subject:      [iText-questions] Action Trigger
> 
> hai...
> 
> 1.
> i tried the code it works fine for triggering action.
> How can i append this to an existing file. ie i would like to add 
> the action trigger to an already existing file. When i tried this 
> the old content gets erased. I have also tried with new 
> FileOutputStream("filename",true) to append but in this case also 
> the result was the same.
> 
> 
> import java.io.*;
> import com.lowagie.text.*;
> import com.lowagie.text.pdf.*;
> 
> class DocOpenAction
> {
>       public static void main(String args[])
>       {
>               Document document = new Document(PageSize.A4, 50, 50, 50, 
> 50);
>          try {
>              PdfWriter writer = PdfWriter.getInstance(document, 
> new FileOutputStream("./chap0304.pdf",true));
>              document.open();
> 
>              writer.setOpenAction(new 
> PdfAction("c:\\winnt\\notepad.exe",null,null,null));
> 
>              document.close();
>              System.out.println("Finished.");
>          }
>          catch (Exception de) {
>              de.printStackTrace();
>          }
>      }
> }
> 
> 2.
> I tried the examples to extract the Note tools and it enables me 
> to extract the title and the content separately. Is it possible to 
> extract it location also.
> My idea is to extract the comments and save it separately and the 
> orginal bare document separately.
> Later when need comes i would like to dynamically populate the 
> original document with the comments(mainly notetools).
> So there i need to put the extracted comments in its orginal 
> location.
> 
> Thanks in Advance.
> Rajesh
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to