Created
August 31, 2011 03:36
-
-
Save lieutar/1182765 to your computer and use it in GitHub Desktop.
PDF::API2 でJavaScript を埋め込むためのもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment