Hi All,

I followed Leonard's suggestion of using addToolButton js sample in SDK.

I am able to create a iconStreamObject using the Acrobat Sample in the SDK
and add it to the toolBar button and my custom button. The image on the
toolBarButton is showing up but not on the custom button.
Note: I used the same js (directly from SDK sample) and made no changes to
it. Also I am not using any XFA form.

Can anybody please suggest what I am doing wrong in the javascript.



         writer.addJavaScript("function openX() {" +
                "try{" +
                " console.show(); "+
                "   app.alert('--------');"+
                "   var strtest=
\"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE4DBD4FF8F9CC8FFD2D3E0FFDBDCD9FFC7E8F9FFC7E8F9FF999FC6FFEEEDEDFFFEFFFFFFB6C8E7FFB2D0E3FFF8F8F8FFFFFFFFFFC2A47BFFD2BC9EFFD0B898FFEEEDEDFFB0AFCDFFE7F2FBFFD1D1D0FFE4E4E4FFC3DAE7FFC7E8F9FF7674A5FFB3C9DCFFAAC4E8FF5D8FC8FFB9D5E6FFD3C9D8FFFEFEFEFFC6AA84FFECE6DFFFFEFDFAFFD2C9C8FFC3DAE7FFB2BFCBFFA4B3C9FF9CB8D9FF7199B3FFA4B3C9FF8A8BBBFF9993A9FFAC9DA7FFA59892FF769BC4FFC6C2B8FFEEEEEFFFC2A47BFFF5F1ECFFAA8657FFD8D6D6FFDAD6E1FFDAD6E1FFCACFD3FF88899AFFB6AAB3FFD8D8D8FFE1E1E1FFE9E9E9FFEEEEEFFFE7E4E5FF31312DFFDCDCDDFFFCFCFCFFF3F3F3FFCDBCA7FFC6C2B8FFE9E9E9FFEEE9E4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FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFEFEFFECECECFF525A58FFC0C1C3FFFEFEFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFEFEFFF3F3F3FF868A8CFFFDFDFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFEFEFFE9E9E9FFF8F8F8FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\";
"+
                " var pos = 0; "+
                " var iconStreamObj = { "+
                "     read: function readMyIcon(nBytes){"+
                "         var t = \"\"; "+
                "         console.println(\"request for \" +nBytes); "+
                "         while (pos < nBytes){ "+
                "              t = t+strtest; "+
                "             pos += strtest.length; "+
                "         } "+
                "         return t; "+
                "     }, "+
                "     width:17, "+
                "     height:20 "+
                " }; "+

                " var f = this.getField(\"Confirm\");"+
                "  f.buttonSetCaption(\"Hello\");"+
                "   f.buttonSetIcon(iconStreamObj,2);"+
                //                 Create a toolbutton using the icon we
loaded above
                "  app.addToolButton "+
                " ({"+
                "     cName: \"myButton\", "+
                "     oIcon: iconStreamObj, "+
                "     cExec: \"app.alert('You have clicked the JavaScript
toolbar button.');\", "+
          "     cTooltext: \"This is my button\", "+
          "     nPos: 0 "+
          " }); "+
                "}catch(e){ app.alert(e);}"+
                "}"
        );
        //bt is the PushbuttonField with fieldName Confirm.
        PdfFormField ff = bt.getField();
        PdfAction ac = PdfAction.javaScript("this.openX();"  , writer);
        ff.setAction(ac);
        writer.addAnnotation(ff);


On Thu, Jul 9, 2009 at 9:16 PM, Leonard Rosenthol <[email protected]>wrote:

>  Check out the AddToolbarButton sample in the SDK for how to create an
> iconStream from an arbitrary string of bytes…
>
>
>
> *From:* Harshit Bapna [mailto:[email protected]]
> *Sent:* Thursday, July 09, 2009 11:30 AM
>
> *To:* Post all your questions about iText here
> *Subject:* Re: [iText-questions] Issue faced while PDFStamping on a XFA
> Form (having javascript) .
>
>
>
> Thanks
> I really appreciate your help.
>
>
>
> Please find my comments inline.
>
> On Thu, Jul 9, 2009 at 8:30 PM, Leonard Rosenthol <[email protected]>
> wrote:
>
> You can do dynamic images in AcroForms using push button appearances – so
> when you using iText to modify the form, you can embed the image at that
> time.  -- I want really dynamic. Earlier I tried to embed the image but it
> didn't flew with my manager. :)
>
>
>
>  Or if you really wanted something more dynamic, you can also use SOAP
> calls from the JavaScript to fetch the image on the fly and assign it to the
> button. -- I followed exactly what your are suggesting the pushbutton
> appearance approach. You r great.
>
>  Using iText I added this js code on button click:
>
>
>
> var response = SOAP.request(
>   {
>  cURL: 'http://10.150.3.131:8080/TestClientWS/services/RegFortAdminSvc',
>  oRequest:
> {'http://stubs.admin.regfort.arcot.com:GetPAMImage':{name:'ABCD'}},
>   bEncoded: false,
>  cNamespace: 'http://stubs.admin.regfort.arcot.com',
>  cResponseStyle: SOAPMessageStyle.Message
>  }
> );
>
> console.show();
> var imgValue = response[0].soapValue[0].soapValue;
> var srcStream = SOAP.streamFromString(imgValue);
> var decodedStream = SOAP.streamDecode(srcStream,\"base64\");
> console.println(this.getField(\"Confirm\").buttonGetCaption());
> app.alert(this.getField(\"Confirm\").buttonGetCaption());
> var f = this.getField(\"Confirm\");
> f.buttonSetCaption(\"Hello\");
> f.buttonSetIcon(decodedStream);    //It requires an Icon object but I am
> not able to create an Icon obj from stream.
>
>
>
> Leonard I am able to set the the buttons caption but not the image. Please
> help me on this.
>
>  Leonard
>
>
>
> *From:* Harshit Bapna [mailto:[email protected]]
> *Sent:* Thursday, July 09, 2009 10:49 AM
>
>
> *To:* Post all your questions about iText here
> *Subject:* Re: [iText-questions] Issue faced while PDFStamping on a XFA
> Form (having javascript) .
>
>
>
> Please find my comments inline
>
> On Thu, Jul 9, 2009 at 7:42 PM, Leonard Rosenthol <[email protected]>
> wrote:
>
>  What do you mean that the image is passed from server?  As you are
> building/modifying the PDF, right?  It’s not coming up dynamically when the
> document loads – that’s not supported any longer (since Acrobat 8, IIRC).
>
>  The server is sending  base64 encoded string and the requirement is that
> the ArcotForm js would assign this encoded string to the image and hence
> displays an image at runtime.
>
> You are correct. I followed this approach as reader 8.1(Security update
> from adobe) or later doesn't allow the HREF approach.
>
>
>
> This is the reason why I want to use XFA form as I was able to achieve
> runtime image display by using ImageField not by AcroForm.
>
>
>
> You can only have one type of form in a PDF – either AcroForm or XFA, you
> can NOT have both.  As long as you have XFA, that will cause Acrobat/Reader
> to ignore any AcroForms that you have created. In your case, that’s the
> pushbutton, which is why it doesn’t work in #3, because as far as
> Acrobat/Reader is concerned, it doesn’t exist.  If you want to add a button
> to your XFA-based form, that’s fine too – you just have to do it using lower
> level functionality with iText and XFA/XML.
>
>  I was just hoping that I can include both the forms as before this xfa
> approach the whole application was using iText to create PDF but as you are
> guiding the acroform won't be recognized. I was wrong in choosing this
> approach :(
>
>    I was using XFA form to only display the image rest everything is done
> through Acroform(iText) .
>
>
>
> Can you give any work around or suggestion to achieve this?
>
>
>
> Leonard
>
>
>
> *From:* Harshit Bapna [mailto:[email protected]]
> *Sent:* Thursday, July 09, 2009 9:48 AM
>
>
> *To:* Post all your questions about iText here
> *Subject:* Re: [iText-questions] Issue faced while PDFStamping on a XFA
> Form (having javascript) .
>
>
>
> Hi All,
>
>
>
> Leonard, Thanks for the reply.
>
>
>
>  Few more additions.
>
> 1) I stamped a pushbutton and javascripts invoked on the buttonClick and
> documentOpen event (using iText) on a XFA form PDF (created using designer
> 8.2) which already had a button and javascript invoked on a button click
> event.
>
>
>
> In the final output :
>
> 1. javascript on button(created using Designer) -- *working*
>
> 2. javascript is getting invoked on document open event(this js was added
> using iText) -- *working*
>
> 3. javascript on button(created using itext) -- *not working*
>
>
>
> This makes me believe that the js on the button is not getting propely set.
> (code in the below mail)
>
> 1) Is it not the case?
>
> 2) Is this XFA-Acroform apporach not feasible ?
>
>
>
> I am deliberately using the XFA form as I wanted to have runtime
> image(base64 encoded string passed from server) display functionality which
> I was able to do using XFA ImageField property.
>
>
>
> --harshit
>
>
>
>
>
> On Thu, Jul 9, 2009 at 5:52 PM, Leonard Rosenthol <[email protected]>
> wrote:
>
> And you can't mix XFA and AcroForm - which is what you are trying to do
> (since PushButton is AcroForm).
>
> Leonard
>
>
> -----Original Message-----
> From: Paulo Soares [mailto:[email protected]]
> Sent: Thursday, July 09, 2009 5:01 AM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Issue faced while PDFStamping on a XFA Form
> (having javascript) .
>
> If you're using a XFA all you can do is fill the fields, that's all iText
> supports.
>
> Paulo
>
> > -----Original Message-----
> > From: Harshit Bapna [mailto:[email protected]]
> > Sent: Thursday, July 09, 2009 9:14 AM
> > To: [email protected]
> > Subject: [iText-questions] Issue faced while PDFStamping on a XFA Form
> > (having javascript) .
> >
> > Hi All,
> >
> > Summary of the Issue: To display an image in PDF at runtime.
> > Limitation: The image cannot be embeded into PDF.
> >
> > Approaches:
> > 1) Using iText and AcroForm I was not able to achieve this.
> > -- Not successfull
> > 2) I designed a form using LC Designer with an ImageField. I assigned
> > the Base64 encoded string to the raw value of this ImageField. It
> > worked -- Successfull
> >
> > I have lot of working code created using iText so I didn't wanted to
> > tamper them. So I came up with this appporach that I would create a
> > base PDF(XFA) using Designer and use PDFStamper to add javascript,
> > button, image, texts.
> >
> > Questions:
> > 1) Is this approach correct/ feasible ?
> >
> > 2) My XFA Pdf (created using Designer) has a javascript. I take this
> > pdf as a base pdf and add a button and document javascript on a button
> > click(suing iText).
> > In the final pdf the button javascript doesn't work.
> >
> > Note: Please be assured that both document javascript and xfa
> > javascript are fine and running but only when they are merged the doc
> > javascript doesn't work.
> > Also I am able to run a document javascript on DOCUMENT OPEN Event but
> > the javascript on button click is not being invoked.
> >
> >
> > Please guide me on the probable cause of the issue? Code Snippet below
> >
> >
> > Code Snippet:
> > public static void main(String[] args) {
> >   try {
> >        PdfReader reader = new PdfReader("C:\\Documents and
> > Settings\\harshit\\Desktop\\baseXFA.pdf");//HelloWorldForm.pdf
> >  HelloWorldForm1.pdf baseXFA.pdf
> >        PdfStamper stamper = new PdfStamper(reader, new
> > FileOutputStream("C:\\Documents and
> > Settings\\harshit\\Desktop\\baseXFAStamped.pdf"));
> >        PdfWriter writer = stamper.getWriter();
> >       XfaForm form = new XfaForm(reader);
> >       System.out.println("XFA Present:" + form.isXfaPresent());
> >       //form.setXfa(writer);
> >       // parsing the dom document and set the values for the required
> > fields
> >       //Document modifiedDoc = parseXdp(form.getDomDocument());
> >
> > stamper.setPageAction(PdfWriter.PAGE_OPEN,PdfAction.javaScript("" +
> >                     "try{" +
> >                     " app.alert(\"doc ready event captured\");"+
> >                     " this.submitActionX();"+
> >                     "}catch(e){}" ,writer),1);
> >
> >       writer.addJavaScript("function submitActionX() {" +
> >       "   console.show();"  +
> >                   "   console.println('---------------------');"  +
> >       " var f = this.getField(\"authX\");"+
> >                   "  f.buttonSetCaption(\"Xhtua\");"+
> >       //"   this.getField(\"userName\").value=\"harshit\";" +
> >                 " }"
> >       );
> >       PushbuttonField button = new PushbuttonField(writer,
> >         new Rectangle(400, 425, 450, 440), "authX"); //230,
> > 80, 360, 110   400, 425, 450, 440   400, 80, 450, 100  230,
> > 150, 360, 160
> >       button.setText("AuthX");
> >       button.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
> >       button.setBackgroundColor(Color.decode("#333399"));
> >       button.setTextColor(Color.WHITE);
> >       button.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
> >       button.setBorderWidth(1);
> >       PdfFormField submit = button.getField();
> >       PdfAction ac =
> > PdfAction.javaScript("this.submitActionX();"  , writer);//
> > form1.authForm.jsex.displayPAMImage() this.open();
> >       //PdfAction ac = PdfAction.javaScript("app.alert('click
> > event captured');"  , writer);//
> > form1.authForm.jsex.displayPAMImage() this.open();
> >       submit.setAction(ac);
> >       stamper.addAnnotation(submit, 1);
> >       BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
> >       BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
> >       TextField tf = new TextField(writer, new Rectangle(300,480, 370,
> > 490), "userName");//67, 500, 340, 800
> >       tf.setFontSize(12);
> >       tf.setFont(bf);
> >       tf.setText("Jaya Kumar");
> >       tf.setTextColor(new GrayColor(0.5f));
> >       stamper.addAnnotation(tf.getTextField(),1);
> >       //stamper.setFormFlattening(true);
> >       stamper.close();
> >   } catch (IOException e) {
> >       e.printStackTrace();
> >   } catch (DocumentException e) {
> >       e.printStackTrace();
> >   } catch (ParserConfigurationException e) {
> >    // TODO Auto-generated catch block
> >       e.printStackTrace();
> >   } catch (SAXException e) {
> >    // TODO Auto-generated catch block
> >      e.printStackTrace();
> >   }
> >  }
> >
> > Thanks
> >
> >
> >
>
> Aviso Legal: Esta mensagem ? destinada exclusivamente ao destinat?rio. Pode
> conter informa??o confidencial ou legalmente protegida. A incorrecta
> transmiss?o desta mensagem n?o significa a perca de confidencialidade. Se
> esta mensagem for recebida por engano, por favor envie-a de volta para o
> remetente e apague-a do seu sistema de imediato. ? proibido a qualquer
> pessoa que n?o o destinat?rio de usar, revelar ou distribuir qualquer parte
> desta mensagem.   Disclaimer: This message is destined exclusively to the
> intended receiver. It may contain confidential or legally protected
> information. The incorrect transmission of this message does not mean the
> loss of its confidentiality. If this message is received by mistake, please
> send it back to the sender and delete it from your system immediately. It is
> forbidden to any person who is not the intended receiver to use, distribute
> or copy any part of this message.
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> 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
> 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/
>
>
>
>
> --
> -- Harshit Bapna
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> 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
> 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/
>
>
>
>
> --
> -- Harshit Bapna
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> 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
> 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/
>
>
>
>
> --
> -- Harshit Bapna
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> 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
> 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/
>



-- 
-- Harshit Bapna
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
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
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