I'm unable to get PDF::Reuse to help me add javascript to a PDF. I'm following very closely one of the examples in the Tutorial.

Since I don't have access to Acrobat (no trial version on OSX) its hard to tell whats going on. I just get an empty looking pdf. (If I omit the prCompress line below and call strings on the doc, I do see the javascript in there). Here is the code:

#!/usr/bin/perl use strict; use warnings; use PDF::Reuse; my $js = do { local $/; <DATA>; }; prDocDir('doc'); prFile('book.pdf'); prCompress(1); prJs($js); prInit('nameAddress();'); prField('First_Name','Lars'); prEnd(); __DATA__ function nameAddress(page, xpos, ypos) { var thePage = 0; if (page) { thePage = page; } var myRec = [ 40, 650, 0, 0]; // default position if (xpos) { myRec[0] = xpos; } if (ypos) { myRec[1] = ypos; } var labelText = [ "First_Name", "Surname", ]; for ( var i = 0; i < labelText.length; i++) { myRec[2] = myRec[0] + 80; // length of the label myRec[3] = myRec[1] - 15; // height // a label field is created var fieldName = labelText[i] + "Label"; var lf1 = this.addField(fieldName, "text", thePage, myRec); lf1.fillColor = color.black; lf1.textColor = color.black; lf1.readonly = true; lf1.textSize = 12; lf1.value = labelText[i]; lf1.display = display.visible; // a text field for the customer // to fill-in his/her name is created myRec[0] = myRec[2] + 2; // move 2 pixels to the right myRec[2] = myRec[0] + 140; // length of the fill-in field var tf1 = this.addField(labelText[i], "text", thePage, myRec); tf1.fillColor = ["RGB", 1, 1, 0.94]; tf1.strokeColor = ["RGB", 0.7, 0.7, 0.6]; tf1.textColor = color.black; tf1.borderStyle = border.s; tf1.textSize = 12; tf1.display = display.visible; myRec[0] = myRec[0] - 82 // move 82 pixels to the left myRec[1] = myRec[1] - 17; // move 17 pixels down } }

Any advice?

qq


In reply to PDF::Reuse - adding javascript by qq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.