Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PDF::API2::JavaScriptSupport;
- use strict;
- use warnings;
- use PDF::API2::Basic::PDF::Utils;
- sub new{
- my ($pkg, $pdf) = @_;
- bless{pdf => $pdf->{pdf}},( ref($pkg) || $pkg );
- }
- sub add{
- my ($this, $script) = @_;
- my $pdf = $this->{pdf};
- my $objs = $pdf->{' objects'};
- my $ref = PDF::API2::Resource->new($pdf);
- my $js = PDF::API2::Resource->new($pdf);
- my ($nref, $gref) = @{$objs->{$ref->uid}}[0,1];
- my ($njs, $gjs ) = @{$objs->{$js->uid}}[0,1];
- delete $js->{Name};
- delete $ref->{Name};
- $js->{'S'} = PDFName('JavaScript');
- $js->{'JS'} = PDFStr($script);
- $ref->{Names} = PDFArray(PDFStr('EmbeddedJS'),
- PDFLiteral($njs. ' '.$gjs.' R'));
- my $cat = $pdf->{Root};
- my $dict = PDFDict();
- $dict->{JavaScript} = PDFLiteral(join " ", $nref, $gref, 'R');
- $cat->{Names} = $dict;
- }
- 1;
- __END__
Add Comment
Please, Sign In to add comment