code: public static PdfAction javaScript(String code, PdfWriter writer, boolean unicode) {
          PdfAction js = new PdfAction();
          js.put(PdfName.S, PdfName.JAVASCRIPT);
          if (unicode && code.length() < 50) {
                  js.put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE));
          }
          else if (!unicode && code.length() < 100) {
                  js.put(PdfName.JS, new PdfString(code));
          }
          else {
              try {
                  byte b[] = PdfEncodings.convertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING);
                  PdfStream stream = new PdfStream(b);
                  stream.flateCompress(writer.getCompressionLevel());
                  js.put(PdfName.JS, writer.addToBody(stream).getIndirectReference());
              }
              catch (Exception e) {
                  js.put(PdfName.JS, new PdfString(code));
              }
          }
          return js;
      }
docs: Creates a JavaScript action. If the JavaScript is smaller than
  50 characters it will be placed as a string, otherwise it will
  be placed as a compressed stream.
  @param code the JavaScript code
  @param writer the writer for this action
  @param unicode select JavaScript unicode. Note that the internal
  Acrobat JavaScript engine does not support unicode,
  so this may or may not work for you
  @return the JavaScript action