Guest User

Untitled

a guest
Jan 23rd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package PDF::API2::JavaScriptSupport;
  2. use strict;
  3. use warnings;
  4. use PDF::API2::Basic::PDF::Utils;
  5.  
  6. sub new{
  7. my ($pkg, $pdf) = @_;
  8. bless{pdf => $pdf->{pdf}},( ref($pkg) || $pkg );
  9. }
  10.  
  11. sub add{
  12. my ($this, $script) = @_;
  13. my $pdf = $this->{pdf};
  14. my $objs = $pdf->{' objects'};
  15. my $ref = PDF::API2::Resource->new($pdf);
  16. my $js = PDF::API2::Resource->new($pdf);
  17. my ($nref, $gref) = @{$objs->{$ref->uid}}[0,1];
  18. my ($njs, $gjs ) = @{$objs->{$js->uid}}[0,1];
  19. delete $js->{Name};
  20. delete $ref->{Name};
  21. $js->{'S'} = PDFName('JavaScript');
  22. $js->{'JS'} = PDFStr($script);
  23. $ref->{Names} = PDFArray(PDFStr('EmbeddedJS'),
  24. PDFLiteral($njs. ' '.$gjs.' R'));
  25. my $cat = $pdf->{Root};
  26. my $dict = PDFDict();
  27. $dict->{JavaScript} = PDFLiteral(join " ", $nref, $gref, 'R');
  28. $cat->{Names} = $dict;
  29. }
  30. 1;
  31. __END__
Add Comment
Please, Sign In to add comment