PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
{<br />
/* Error handling */<br />
return;<br />
}<br />
p.begin_page_ext(pagewidth, pageheight, "");<br />
...<br />
String optlist = "action={up " + print_action + "} icon=" + print_icon +<br />
" tooltip={Print the document} font=" + button_font;<br />
p.create_field(left_x, left_y, right_x, right_y, "print_button", "pushbutton", optlist);<br />
Cookbook A full code sample can be found in the Cookbook topic interactive/form_pushbutton.<br />
Simple text field. Now we create a text field near the upper right corner of the page.<br />
The user will be able to enter the current date in this field. We acquire a font handle and<br />
create a form field of type textfield which is called date, and has a gray background:<br />
textfield_font = p.load_font("Helvetica-Bold", "unicode", "");<br />
String optlist = "backgroundcolor={gray 0.8} font=" + textfield_font;<br />
p.create_field(left_x, left_y, right_x, right_y, "date", "textfield", optlist);<br />
By default the font size is auto, which means that initially the field height is used as the<br />
font size. When the input reaches the end of the field the font size is decreased so that<br />
the text always fits into the field.<br />
Cookbook Full code samples can be found in the Cookbook topics in teractive/form_textfield_layout<br />
and interactive/form_textfield_height.<br />
Text field with JavaScript. In order to improve the text form field created above we automatically<br />
fill it with the current date when the page is opened. First we create an action<br />
of type JavaScript (in Acrobat: Run a JavaScript). The script option in the action’s option<br />
list defines a JavaScript snippet which displays the current date in the date text<br />
field in the format month-day-year:<br />
String optlist =<br />
"script={var d = util.printd('mmm dd yyyy', new Date()); "<br />
"var date = this.getField('date'); date.value = d;}"<br />
show_date = p.create_action("JavaScript", optlist);<br />
In the second step we create the page. In the option list we supply the action option<br />
which attaches the show_date action created above to the trigger event open (in Acrobat:<br />
Page Open):<br />
String optlist = "action={open " + show_date + "}";<br />
p.begin_page_ext(pagewidth, pageheight, optlist);<br />
Finally we create the text field as we did above. It will automatically be filled with the<br />
current date whenever the page is opened:<br />
textfield_font = p.load_font("Helvetica-Bold", "winansi", "");<br />
String optlist = "backgroundcolor={gray 0.8} font=" + textfield_font;<br />
p.create_field(left_x, left_y, right_x, right_y, "date", "textfield", optlist);<br />
90 Chapter 3: Creating PDF Documents (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)