| PDF-API2 documentation | Contained in the PDF-API2 distribution. |
PDF::API2::Lite - lite pdf creation
$pdf = PDF::API2::Lite->new;
$pdf->page(595,842);
$img = $pdf->image('some.jpg');
$font = $pdf->corefont('Times-Roman');
$font = $pdf->ttfont('TimesNewRoman.ttf');
Opens a new page.
Sets the global mediabox.
Saves the document (may not be modified later) and deallocates the pdf-structures.
Returns a new or existing adobe core font object.
Examples:
$font = $pdf->corefont('Times-Roman');
$font = $pdf->corefont('Times-Bold');
$font = $pdf->corefont('Helvetica');
$font = $pdf->corefont('ZapfDingbats');
Returns a new or existing truetype font object.
Examples:
$font = $pdf->ttfont('TimesNewRoman.ttf');
$font = $pdf->ttfont('/fonts/Univers-Bold.ttf');
$font = $pdf->ttfont('../Democratica-SmallCaps.ttf');
Returns a new type1 font object.
Examples:
$font = $pdf->psfont('TimesRoman.pfb','TimesRoman.afm','latin1');
$font = $pdf->psfont('/fonts/Univers.pfb','/fonts/Univers.afm','latin2');
Returns a new extended-graphics-state object.
Examples:
$egs = $pdf->create_egs;
Returns a new jpeg-image object.
Returns a new png-image object.
Returns a new tiff-image object.
Returns a new pnm-image object.
Saves the state of the page.
Restores the state of the page.
Sets extended-graphics-state.
Sets fillcolor.
Sets strokecolor.
Defined color-names are:
aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond,
blue, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue,
cornsilk, crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkgrey,
darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon,
darkseagreen, darkslateblue, darkslategray, darkslategrey, darkturquoise, darkviolet,
deeppink, deepskyblue, dimgray, dimgrey, dodgerblue, firebrick, floralwhite, forestgreen,
fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, grey, green, greenyellow, honeydew,
hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon,
lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgreen, lightgrey,
lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightslategrey,
lightsteelblue, lightyellow, lime, limegreen, linen, magenta, maroon, mediumaquamarine,
mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite,
navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen,
paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple,
red, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna,
silver, skyblue, slateblue, slategray, slategrey, snow, springgreen, steelblue, tan, teal,
thistle, tomato, turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen
or the rgb-hex-notation:
#rgb, #rrggbb, #rrrgggbbb and #rrrrggggbbbb
or the cmyk-hex-notation:
%cmyk, %ccmmyykk, %cccmmmyyykkk and %ccccmmmmyyyykkkk
or the hsl-hex-notation:
&hsl, &hhssll, &hhhssslll and &hhhhssssllll
and additionally the hsv-hex-notation:
!hsv, !hhssvv, !hhhsssvvv and !hhhhssssvvvv
Sets linedash.
Sets linewidth.
Sets transformations (eg. translate, rotate, scale, skew) in pdf-canonical order.
Example:
$pdf->transform(
-translate => [$x,$y],
-rotate => $rot,
-scale => [$sx,$sy],
-skew => [$sa,$sb],
)
Please Note: The width/height or scale given is in user-space coordinates which is subject to transformations which may have been specified beforehand.
Per default this has a 72dpi resolution, so if you want an image to have a 150 or 300dpi resolution, you should specify a scale of 72/150 (or 72/300) or adjust width/height accordingly.
Applys the given text.
Convenience wrapper for shortening the textstart..textend sequence.
alfred reibenschuh
| PDF-API2 documentation | Contained in the PDF-API2 distribution. |
package PDF::API2::Lite; our $VERSION = '2.019'; BEGIN { use PDF::API2; use PDF::API2::Util; use PDF::API2::Basic::PDF::Utils; use POSIX qw( ceil floor ); use vars qw( $hasWeakRef ); } no warnings qw[ deprecated recursion uninitialized ];
sub new { my $class=shift(@_); my %opt=@_; my $self={}; bless($self,$class); $self->{api}=PDF::API2->new(@_); return $self; }
sub page { my $self=shift; $self->{page}=$self->{api}->page; $self->{page}->mediabox(@_) if($_[0]); $self->{gfx}=$self->{page}->gfx; # $self->{gfx}->compressFlate; return $self; }
sub mediabox { my ($self,$x1,$y1,$x2,$y2) = @_; if(defined $x2) { $self->{api}->mediabox($x1,$y1,$x2,$y2); } else { $self->{api}->mediabox($x1,$y1); } $self; }
sub saveas { my ($self,$file)=@_; if($file eq '-') { return $self->{api}->stringify; } else { $self->{api}->saveas($file); return $self; } $self->{api}->end; foreach my $k (keys %{$self}) { if(UNIVERSAL::can($k,'release')) { $k->release(1); } elsif(UNIVERSAL::can($k,'end')) { $k->end; } $self->{$k}=undef; delete($self->{$k}); } return undef; }
sub corefont { my ($self,$name,@opts)=@_; my $obj=$self->{api}->corefont($name,@opts); return $obj; }
sub ttfont { my ($self,$file,@opts)=@_; return $self->{api}->ttfont($file,@opts); }
sub psfont { my ($self,@args)=@_; return $self->{api}->psfont(@args); } #=item @color = $pdf->color $colornumber [, $lightdark ] # #=item @color = $pdf->color $basecolor [, $lightdark ] # #Returns a color. # #B<Examples:> # # @color = $pdf->color(0); # 50% grey # @color = $pdf->color(0,+4); # 10% grey # @color = $pdf->color(0,-3); # 80% grey # @color = $pdf->color('yellow'); # yellow, fully saturated # @color = $pdf->color('red',+1); # red, +10% white # @color = $pdf->color('green',-2); # green, +20% black # #=cut # #sub color { # my $self=shift @_; # return $self->{api}->businesscolor(@_); #}
sub create_egs { my ($self)=@_; return $self->{api}->egstate; }
sub image_jpeg { my ($self,$file)=@_; return $self->{api}->image_jpeg($file); }
sub image_png { my ($self,$file)=@_; return $self->{api}->image_png($file); }
sub image_tiff { my ($self,$file)=@_; return $self->{api}->image_tiff($file); }
sub image_pnm { my ($self,$file)=@_; return $self->{api}->image_pnm($file); }
sub savestate { my $self=shift @_; $self->{gfx}->save; }
sub restorestate { my $self=shift @_; $self->{gfx}->restore; }
sub egstate { my $self=shift @_; $self->{gfx}->egstate(@_); return($self); }
sub fillcolor { my $self=shift @_; $self->{gfx}->fillcolor(@_); return($self); }
sub strokecolor { my $self=shift @_; $self->{gfx}->strokecolor(@_); return($self); }
sub linedash { my ($self,@a)=@_; $self->{gfx}->linedash(@a); return($self); }
sub linewidth { my ($self,$linewidth)=@_; $self->{gfx}->linewidth($linewidth); return($self); }
sub transform { my ($self,%opt)=@_; $self->{gfx}->transform(%opt); return($self); }
sub move { # x,y ... my $self=shift @_; $self->{gfx}->move(@_); return($self); }
sub line { # x,y ... my $self=shift @_; $self->{gfx}->line(@_); return($self); }
sub curve { # x1,y1,x2,y2,x3,y3 ... my $self=shift @_; $self->{gfx}->curve(@_); return($self); }
sub arc { # x,y,a,b,alf,bet[,mov] my $self=shift @_; $self->{gfx}->arc(@_); return($self); }
sub ellipse { my $self=shift @_; $self->{gfx}->ellipse(@_); return($self); }
sub circle { my $self=shift @_; $self->{gfx}->circle(@_); return($self); }
sub rect { # x,y,w,h ... my $self=shift @_; $self->{gfx}->rect(@_); return($self); }
sub rectxy { my $self=shift @_; $self->{gfx}->rectxy(@_); return($self); }
sub poly { my $self=shift @_; $self->{gfx}->poly(@_); return($self); }
sub close { my $self=shift @_; $self->{gfx}->close; return($self); }
sub stroke { my $self=shift @_; $self->{gfx}->stroke; return($self); }
sub fill { # nonzero my $self=shift @_; $self->{gfx}->fill; return($self); }
sub fillstroke { # nonzero my $self=shift @_; $self->{gfx}->fillstroke; return($self); }
sub image { my $self=shift @_; $self->{gfx}->image(@_); return($self); }
sub textstart { my $self=shift @_; $self->{gfx}->textstart; return($self); }
sub textfont { my $self=shift @_; $self->{gfx}->font(@_); return($self); }
sub textlead { my $self=shift @_; $self->{gfx}->lead(@_); return($self); }
sub text { my $self=shift @_; return $self->{gfx}->text(@_)||$self; }
sub nl { my $self=shift @_; $self->{gfx}->nl; return($self); }
sub textend { my $self=shift @_; $self->{gfx}->textend; return($self); }
sub print { my $self=shift @_; my ($font, $size, $x, $y, $rot, $just, @text)=@_; my $text=join(' ',@text); $self->textstart; $self->textfont($font, $size); $self->transform( -translate=>[$x, $y], -rotate=> $rot, ); if($just==1) { $self->{gfx}->text_center($text); } elsif($just==2) { $self->{gfx}->text_right($text); } else { $self->text(@text); } $self->textend; return($self); } 1; __END__