use strict; use warnings; use feature 'say'; use CAM::PDF; sub _n { CAM::PDF::Node-> new( @_ )} my $js_code = << 'EO_JS'; this.getField("AfterSave1").display = display.hidden; this.getField("AfterSave2").display = display.hidden; this.dirty=false; EO_JS my $file = $ARGV[ 0 ] or die; my $pdf = CAM::PDF-> new( $file ) or die; my $root = $pdf-> getRootDict; my $names_dict = $pdf-> getValue( $root-> { Names }); my $js_tree = $pdf-> getValue( $names_dict-> { JavaScript }); my $js_tree_root_ary = $pdf-> getValue( $js_tree-> { Names }); my $js_code_stream = $pdf-> createStreamObject( $js_code, 'FlateDecode' ); my $js_code_obj = $pdf-> appendObject( undef, $js_code_stream, 0 ); my $js_code_ref = _n( reference => $js_code_obj ); my $js_action_dict = _n( dictionary => { JS => $js_code_ref, S => _n( label => 'JavaScript' ), }); my $js_action_obj = $pdf-> appendObject( undef, _n( object => $js_action_dict ), 0 ); my $js_action_ref = _n( reference => $js_action_obj ); my $js_code_name = _n( label => 'my_js_code' ); push @{ $js_tree_root_ary }, $js_code_name, $js_action_ref; $file =~ s/\.pdf$/++$&/i; $pdf-> cleanoutput( $file );