/** 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 */ public static PdfAction javaScript(string code, PdfWriter writer, bool 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.ENCODING); PdfStream stream = new PdfStream(b); stream.flateCompress(); js.put(PdfName.JS, writer.addToBody(stream).IndirectReference); } catch (Exception e) { throw e; } } return(js); }
public static PdfAction createImportData(string file) { PdfAction action = new PdfAction(); action.put(PdfName.S, PdfName.IMPORTDATA); action.put(PdfName.F, new PdfString(file)); return(action); }
/** Creates a GoTo action to an internal page. * @param page the page to go. First page is 1 * @param dest the destination for the page * @param writer the writer for this action * @return a GoTo action */ public static PdfAction gotoLocalPage(int page, PdfDestination dest, PdfWriter writer) { PdfIndirectReference piref = writer.getPageReference(page); dest.addPage(piref); PdfAction action = new PdfAction(); action.put(PdfName.S, PdfName.GOTO); action.put(PdfName.D, dest); return(action); }
public static PdfAction createResetForm(Object[] names, int flags) { PdfAction action = new PdfAction(); action.put(PdfName.S, PdfName.RESETFORM); if (names != null) { action.put(PdfName.FIELDS, buildArray(names)); } action.put(PdfName.FLAGS, new PdfNumber(flags)); return(action); }
internal static PdfAction createHide(PdfObject obj, bool hide) { PdfAction action = new PdfAction(); action.put(PdfName.S, PdfName.HIDE); action.put(PdfName.T, obj); if (!hide) { action.put(PdfName.H, PdfBoolean.PDFFALSE); } return(action); }
public static PdfAction createSubmitForm(string file, Object[] names, int flags) { PdfAction action = new PdfAction(); action.put(PdfName.S, PdfName.SUBMITFORM); PdfDictionary dic = new PdfDictionary(); dic.put(PdfName.F, new PdfString(file)); dic.put(PdfName.FS, PdfName.URL); action.put(PdfName.F, dic); if (names != null) { action.put(PdfName.FIELDS, buildArray(names)); } action.put(PdfName.FLAGS, new PdfNumber(flags)); return(action); }