Thanks a lot for your answer.

I have studied the code snippet of Bruno Lowagie as you advised me, but
I didn't have success. I failed even to program the reading of JavaScript which
lies behind buttons. The problem is that sometimes the JavaScript is in
a stream. In this case I easily get an indirect reference to the stream object.
But if I try to resolve this indirect reference with PdfReader.getPdfObject, the
resulting stream object is empty.

I have my code attached to this mail.

What is wrong with my approach?

Yours sincerly
Joachim Sieglen
Java-Entwickler

Form-Solutions
Winzerstr. 54
D-75217 Birkenfeld-Grafenhausen

Fon: +49 7082 9464-0
Fax: +49 7082 9464-17

http://www.form-solutions.de
mailto:[EMAIL PROTECTED]

Inhaber und Geschaftsleitung: Matthias Eisenblatter
Ust-IdNr.: DE207718873, SteuerNr.: 49129/42507











        -----Ursprungliche Nachricht-----
        Von: 1T3XT info mailto:[EMAIL PROTECTED]
        Gesendet: 14.08.2008 16:21:24
        An: Post all your questions about iText here 
mailto:[email protected]
        Betreff: Re: [iText-questions] Re ading and writing Javascript
        
        Joachim Sieglen wrote:
        > Hello everybody,
        > 
        > I have to change (reading, modifiying and writing back) Javascript 
which is
        > no document-level Javascript but lies behind a button (and is 
executed when
        > the button is clicked). Is there a way to do this programmatically 
using
        > iText?
        
        Your question was already answered (and correct me if I'm
        wrong, but it was in answer to one of your questions):
        http://1t3xt.info/examples/browse/?page=example&id=372
        -- 
        This answer is provided by 1T3XT BVBA
        
        
-------------------------------------------------------------------------
        This SF.Net email is sponsored by the Moblin Your Move Developer's 
challenge
        Build the coolest Linux based applications with Moblin SDK & win great 
prizes
        Grand prize is a trip for two to an Open Source event anywhere in the 
world
        http://moblin-contest.org/redirect.php?banner_id=100&url=/
        _______________________________________________
        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
        
        No virus found in this incoming message.
        Checked by AVG - http://www.avg.com 
        Version: 8.0.138 / Virus Database: 270.6.3/1610 - Release Date: 
13.08.2008 16:14
        
        
        
        public void readAndWriteJS(AcroFields fieldsAF) {
                
                HashMap fieldsHM = fieldsAF.getFields();
                String itemKey = null;
                
                try {
                        for (Iterator it=fieldsHM.keySet().iterator(); 
it.hasNext(); ){
                                itemKey = (String)it.next();
                                if 
(fieldsAF.getFieldType(itemKey)==fieldsAF.FIELD_TYPE_PUSHBUTTON) {
                                        System.out.println("Button: " + 
itemKey);
                                        Item itemField = 
fieldsAF.getFieldItem(itemKey);
                                        for (int i=0; 
i<itemField.widget_refs.size(); i++){
                                                PdfDictionary dictItem = 
(PdfDictionary) PdfReader.getPdfObject((PdfObject) 
itemField.widget_refs.get(i));
                                                PdfDictionary dictA = 
(PdfDictionary) PdfReader.getPdfObject(dictItem.get(PdfName.A));
                                                if (dictA != null) {
                                                        if 
(dictA.get(PdfName.S) != null) {
                                                                
System.out.println(dictA.get(PdfName.S).toString());
                                                                if 
(dictA.get(PdfName.S).toString().equals("/JavaScript")) {
                                                                        
PdfObject jsObj = dictA.get(PdfName.JS);
                                                                        
//System.out.println(jsObj.type());
                                                                        if 
(jsObj.isString())
                                                                                
System.out.println((dictA.get(PdfName.JS)).toString());
                                                                        else if 
(jsObj.isIndirect()) {
                                                                                
PRStream jsStream = (PRStream) PdfReader.getPdfObject(jsObj);
                                                                                
ByteArrayOutputStream os = new ByteArrayOutputStream();
                                                                                
jsStream.writeContent(os);
                                                                                
System.out.println("Stream: " + jsStream.getBytes().toString());
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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