10.07.2015 Views

Download - Multivac!

Download - Multivac!

Download - Multivac!

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Cookbook A full code sample can be found in the Cookbook topic interactive/nested_bookmarks.Annotation with file attachment. In the next example we create a file attachment. Westart by creating an annotation of type FileAttachment. The filename option specifies thename of the attachment, the option mimetype image/gif specifies its type (MIME is acommon convention for classifying file contents). The annotation will be displayed as apushpin (iconname pushpin) in red (annotcolor {rgb 1 0 0}) and has a tooltip (contents {Getthe Kraxi Paper Plane!}). It will not be printed (display noprint):String optlist ="filename=kraxi_logo.gif mimetype=image/gif iconname=pushpin " +"annotcolor={rgb 1 0 0} contents={Get the Kraxi Paper Plane!} display=noprint";p.create_annotation(left_x, left_y, right_x, right_y, "FileAttachment", optlist);Note that the size of the symbol defined with iconname does not vary; the icon will bedisplayed in its standard size in the top left corner of the specified rectangle.Button form field for printing. The next example creates a button form field whichcan be used for printing the document. In the first version we add a caption to the button;later we will use a printer symbol instead of the caption. We start by creating an actionof type Named (in Acrobat: Execute a menu item). Also, we must specify the font forthe caption:print_action = p.create_action("Named", "menuname=Print");button_font = p.load_font("Helvetica-Bold", "unicode", "");The action option for the button form field contains the up event (in Acrobat: Mouse Up)as a trigger for executing the action, plus the print_action handle created above for theaction itself. The backgroundcolor {rgb 1 1 0} option specifies yellow background, whilebordercolor {rgb 0 0 0} specifies black border. The option caption Print adds the text Printto the button, and tooltip {Print the document} creates an additional explanation for theuser. The font option specifies the font using the button_font handle created above. Bydefault, the size of the caption will be adjusted so that it completely fits into the button’sarea. Finally, the actual button form field is created with proper coordinates, thename print_button, the type pushbutton and the appropriate options:String optlist ="action {up " + print_action + "} backgroundcolor={rgb 1 1 0} " +"bordercolor={rgb 0 0 0} caption=Print tooltip={Print the document} font=" +button_font;p.create_field(left_x, left_y, right_x, right_y, "print_button", "pushbutton", optlist);Now we extend the first version of the button by replacing the text Print with a littleprinter icon. To achieve this we load the corresponding image file print_icon.jpg as atemplate before creating the page. Using the icon option we assign the template handleprint_icon to the button field, and create the form field similarly to the code above:print_icon = p.load_image("auto", "print_icon.jpg", "template");if (print_icon == -1){/* Error handling */return;3.4 Interactive Elements 69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!