<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package PDF::API2::Simple;

=head1 NAME

PDF::API2::Simple - Simplistic wrapper for the excellent PDF::API2 modules

=head1 SYNOPSIS

    use PDF::API2::Simple;

    my $pdf = PDF::API2::Simple-&gt;new( 
                                     file =&gt; 'output.pdf'
                                    );

    $pdf-&gt;add_font('VerdanaBold');
    $pdf-&gt;add_font('Verdana');
    $pdf-&gt;add_page();

    $pdf-&gt;link( 'http://search.cpan.org', 'A Hyperlink',
                x =&gt; 350,
                y =&gt; $pdf-&gt;height - 150 );

    for (my $i = 0; $i &lt; 250; $i++) {
         my $text = "$i - All work and no play makes Jack a dull boy";

         $pdf-&gt;text($text, autoflow =&gt; 'on');
    }

    $pdf-&gt;save();

Note that this module aims to be simple, not accurate or efficent, though it is mostly both. I like
the PDF::API2 modules, but I find, and suspect others do also, that they are difficult to use and lack 
documentation. This module was written with PDF creation in mind, though it is certainly possible to 
update existing PDF files with this module.

Take note that PDF coordinates are not quite what you're used to. The coordinate, (0, 0) for instance is at
the lower-left hand corner. Thus, x still grows to the right, but y grows towards the top.

=head1 METHODS

=cut

$VERSION = '1.0.3';

use strict;
use PDF::API2;

require Exporter;
require Carp;

our @ISA = qw(Exporter);

=head2 new

     PDF::API2::Simple-&gt;new(
		 'file' =&gt; 'output.txt',
		 'width' =&gt; 612,
		 'height' =&gt; 792,
		 'line_height' =&gt; 10,
		 'margin_left' =&gt; 20,
		 'margin_top' =&gt; 20,
		 'margin_right' =&gt; 20,
		 'margin_bottom' =&gt; 50,
		 'width_right' =&gt; 0,
		 'height_bottom' =&gt; 0,
		 'effective_width' =&gt; 0,
		 'effective_height' =&gt; 0,
		 'header' =&gt; undef,
		 'footer' =&gt; undef,
     );

Creates a new PDF::API2::Simple instance. A good strategy is to create a new object for each
pdf file you want to create. That is, of course, up to you.

=over

=item * file - The PDF file you want to write to. No default, parameter required

=item * width - The width of the PDF file. Defaults to 612, the 8 1/2 x 11 US Letter width

=item * height - The height of the PDF file. Defaults to 792, the 8 1/2 x 11 US Letter height

=item * line_height - The standard height you want to define for lines. The default is 10

=item * margin_left - The amount of margin space you want on the left side. Of course, you can specify whatever coordniates you want. Default is 20

=item * margin_top - The amount of margin space you want on the top of each page. Default is 20

=item * margin_right - The amount of margin space you want of the right side of each page. Default is 20

=item * margin_bottom - The amount of margin space you want on the bottom of each page. Default is 50

=item * width_right - A convenience property that contains the furthest I&lt;x&gt; of the page, accounting for the margins specified

=item * height_bottom - A convenience property that contains the largest C&lt;y&gt; of the page, accounting for the bottom margin

=item * effective_width - A convenience property that contains the width of the page, after the left and right margin have been accounted for

=item * effective_height - A convenience property that contains the height of the page, after the top and bottom margin have been accounted for

=item * header - This C&lt;CODE&gt; reference will be called everytime a page is appended to the PDF, allowing you to specifiy a header for your pages

=item * footer - This C&lt;CODE&gt; reference will be called everytime a page is ended, allowing you to specifiy a footer for your pages

=back

=cut

sub new {
  my ($self, %opts) = @_;

  Carp::croak("file is required") if (!$opts{'file'});

  $self = bless {
		 'file' =&gt; $opts{'file'},
		 'width' =&gt; $opts{'width'} || 612,
		 'height' =&gt; $opts{'height'} || 792,
		 'line_height' =&gt; $opts{'line_height'} || 10,
		 'margin_left' =&gt; $opts{'margin_left'} || 20,
		 'margin_top' =&gt; $opts{'margin_top'} || 20,
		 'margin_right' =&gt; $opts{'margin_right'} || 20,
		 'margin_bottom' =&gt; $opts{'margin_bottom'} || 50,
		 'width_right' =&gt; 0,
		 'height_bottom' =&gt; 0,
		 'effective_width' =&gt; 0,
		 'effective_height' =&gt; 0,
		 'header' =&gt; $opts{'header'} || undef,
		 'footer' =&gt; $opts{'footer'} || undef,
		 
		 '_pdf'  =&gt; PDF::API2-&gt;new( '-file' =&gt; $opts{'file'} ),
		 '_fonts' =&gt; { },

		 '_x' =&gt; 0,
		 '_y' =&gt; 0,
		 '_current_page' =&gt; 0,
		 '_current_font' =&gt; undef,
		 '_current_font_size' =&gt; 10,
		 '_current_stroke_color' =&gt; 'black',
		 '_current_fill_color' =&gt; 'black'
		}, $self;

  $self-&gt;_set_relative_values();
  $self-&gt;_reset_x_and_y();

  return $self;
}

# private methods
# ================================================

sub _reset_x_and_y {
  my $self = shift;

  $self-&gt;{'_x'} = $self-&gt;margin_left;
  $self-&gt;{'_y'} = ($self-&gt;height - $self-&gt;margin_top);
}

sub _set_relative_values {
  my $self = shift;

  $self-&gt;{'width_right'} = $self-&gt;width - $self-&gt;margin_right;
  $self-&gt;{'height_bottom'} = $self-&gt;height - $self-&gt;margin_bottom;
  $self-&gt;{'effective_width'} = ($self-&gt;width - ($self-&gt;margin_left + $self-&gt;margin_right));
  $self-&gt;{'effective_height'} = ($self-&gt;height - ($self-&gt;margin_top + $self-&gt;margin_bottom));
}

sub _add_page_if_exceeds_bounds {
  my ($self, $theoretical_y) = @_;

  if ($self-&gt;would_extend_page( $theoretical_y )) {
    $self-&gt;add_page();

    return 1;
  }

  return 0;
}

sub _get_text_object_for_current_page {
  my ($self, %opts) = @_;
  my $font = ((exists $opts{'font'} &amp;&amp; $opts{'font'}) ? $self-&gt;fonts-&gt;{$opts{'font'}} : $self-&gt;current_font);
  my $font_size = $opts{'font_size'} || $opts{'fontsize'} || $self-&gt;current_font_size;
  my $stroke_color = $opts{'stroke_color'} || $opts{'strokecolor'} || $self-&gt;current_stroke_color;
  my $fill_color = $opts{'fill_color'} || $opts{'fillcolor'} || $self-&gt;current_fill_color;
  my $text_obj = $self-&gt;current_page-&gt;text();

  $self-&gt;current_font( $font );
  $self-&gt;current_font_size( $font_size );
  $self-&gt;current_stroke_color( $stroke_color );
  $self-&gt;current_fill_color( $fill_color );

  $text_obj-&gt;font( $font, $font_size );
  $text_obj-&gt;strokecolor( $stroke_color );
  $text_obj-&gt;fillcolor( $fill_color );

  return $text_obj;
}

sub _render_text_at {
  my ($self, $text_obj, $text, $x, $y, $align) = @_;

  $text_obj-&gt;translate( $x, $y );

  if (lc $align eq 'center') {
    my $width = $text_obj-&gt;text_center( $text );

    if (wantarray) {
      my $half_w = $width / 2;
      my $rect_x = $x - $half_w;
      my $rect_x_to = $x + $half_w;

      return ( $rect_x, $y, $rect_x_to, $y + $self-&gt;current_font_size );
    }

    return $width; 
  }

  if (lc $align eq 'right') {
    my $width = $text_obj-&gt;text_right( $text );

    if (wantarray) {
      my $rect_x = $x - $width;
      my $rect_x_to = $x;

      return ( $rect_x, $y, $rect_x_to, $y + $self-&gt;current_font_size );
    }

    return $width;
  }

  if (wantarray) {
    my $width = $text_obj-&gt;text( $text );
    my $rect_x = $x;
    my $rect_x_to = $x + $width;

    return ( $rect_x, $y, $rect_x_to, $y + $self-&gt;current_font_size );
  }
  else {
    return $text_obj-&gt;text( $text );
  }
}

sub _standard_content_opts {
  my ($self, $content, %opts) = @_;

  my $stroke_color = $opts{'stroke_color'} || $opts{'strokecolor'} || $self-&gt;current_stroke_color;
  my $fill_color = $opts{'fill_color'} || $opts{'fillcolor'} || $self-&gt;current_fill_color;
  my $width = $opts{'width'} || 0.5;

  $content-&gt;strokecolor( $stroke_color );
  $content-&gt;fillcolor( $fill_color );
  $content-&gt;linewidth( $width );
}

sub _render_content {
  my ($self, $content, %opts) = @_;

  my $stroke = lc $opts{'stroke'};
  my $fill = lc $opts{'fill'};

  $stroke = 'on' if (($stroke eq 'yes') || ($stroke eq 'true'));
  $fill = 'on' if (($fill eq 'yes') || ($fill eq 'true'));

  if ((!$stroke &amp;&amp; !$fill) || (($stroke eq 'off') &amp;&amp; ($fill eq 'off'))) {
    $fill = 'on'; # default to fill, not stroke
  }

  if ((lc $stroke eq 'on') &amp;&amp; (lc $fill eq 'on')) {
    $content-&gt;fillstroke();
  }
  elsif (lc $fill eq 'on') {
    $content-&gt;fill();
  }
  elsif (lc $stroke eq 'on') {
    $content-&gt;stroke();
  }
}

sub _limit_text {
  my ($self, $text, $limit) = @_;
  my @chars;
  my $index;

  return $text if (length($text) &lt;= $limit);

  @chars = split //, $text;
  $index = int(scalar(@chars) * 0.75);

  Carp::croak( "Limit must be &gt; than 5" ) if ($limit &lt; 5);

  $text = join '', @chars;

  while (scalar(@chars) &gt; $limit) {
    splice(@chars, $index--, 1);

    last if ($index &lt; 0);
  }

  $text = join '', @chars;
  substr($text, $index, 3) = '...'; 

  return $text;
}

# public methods - space management
# ================================================

=head2 Space Management

The following methods help you to manage the space on each page of your PDF.

=head3 next_line_would_extend_page

Returns a true value if the current C&lt;y&gt; minus C&lt;line_height&gt; would write past the bottom margin.

=cut

sub next_line_would_extend_page {
  my $self = shift;

  return $self-&gt;would_extend_page( $self-&gt;y - $self-&gt;line_height );
}

=head3 would_extend_page C&lt;theoretical_y&gt;

Returns a true value if the current C&lt;y&gt; minus C&lt;theoretical_y&gt; would write past the bottom margin.

=cut

sub would_extend_page {
  my ($self, $theoretical_y) = @_;

  return ($theoretical_y &lt; $self-&gt;margin_bottom);
}

=head3 next_line

Reduces the current C&lt;y&gt; by C&lt;line_height&gt;.

=cut

sub next_line {
  my $self = shift;

  $self-&gt;{'_y'} -= $self-&gt;line_height;
}

=head3 add_page

Closes the current page, resets the C&lt;x&gt; and C&lt;y&gt; values to thier default coordinates, and calls the header callback, if specified. This method may be called for in, such as if your autoflow text wraps over a page.

=cut

sub add_page {
  my $self = shift;
  
  if ($self-&gt;current_page) {
    $self-&gt;end_page();
  }    

  $self-&gt;current_page( $self-&gt;pdf-&gt;page() );
  $self-&gt;_reset_x_and_y();

  if ($self-&gt;header) {
    $self-&gt;header-&gt;( $self );
  }
}

=head3 end_page

Closes the current page, and calls the footer callback, if specified. This method is usually called for you.

=cut

sub end_page {
  my $self = shift;

  if ($self-&gt;footer) {
    $self-&gt;footer-&gt;( $self );
  }
}

# public methods - general mangement
# ================================================

=head2 General Management

These methods help you manage the PDF itself

=head3 add_font C&lt;font_name&gt;

This method will add a font to be used throughout the PDF. You C&lt;MUST&gt; call this at least once before laying out your PDF. C&lt;font_name&gt; is a font name, such as 'Arial', or 'Verdana'. Appending 'Bold' seems to make the text bold, as in 'VerdanaBold'. Refer to L&lt;PDF::API2&gt; for more details.

=cut

sub add_font {
  my ($self, $font_name) = @_;

  $self-&gt;fonts-&gt;{$font_name} = $self-&gt;pdf-&gt;corefont($font_name);
  $self-&gt;current_font( $self-&gt;fonts-&gt;{$font_name} );
}

=head3 set_font C&lt;font_name&gt;[, C&lt;pt&gt;]

Set the current font by name, and optionally a font size.

=cut

sub set_font {
  my ($self, $font_name, $pt) = @_;

  $self-&gt;current_font( $self-&gt;fonts-&gt;{$font_name} );

  if ($pt &amp;&amp; ($pt &gt; 0)) {
    $self-&gt;current_font_size( $pt );
  }
}

=head3 save

End the current page, and save the document to the file specified when instaniating the object.

=cut

sub save {
  my $self = shift;

  $self-&gt;end_page();
  $self-&gt;{'_pdf'}-&gt;save;
}

# public methods - layout
# ================================================

=head2 Layout

These methods modify the actual layout of the PDF. Note that most of these methods set some internal state. Most often, the last C&lt;x&gt; and C&lt;y&gt; are set after the rendered object.

Most times, underscores may be stripped and the arguments will still work, such as is the difference between C&lt;fill_color&gt;, and C&lt;fillcolor&gt;.

=head3 popup C&lt;text&gt;[, C&lt;%opts&gt;]

Creates a 25x25 box at C&lt;opts{x}&gt; (or the current C&lt;x&gt;), C&lt;opts{y}&gt; (or the current C&lt;y&gt;) to represent an annotation at that point. The user may then click that icon for a full annotation.

=cut

sub popup {
  my ($self, $text, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $annotation = $self-&gt;current_page-&gt;annotation;
  
  $annotation-&gt;rect( $x, $y, $x + 25, $y + 25 );
  $annotation-&gt;text( $text );
}

=head3 url

This is an alias for the C&lt;link&gt; method.

=cut

sub url {
  my $self = shift;

  return $self-&gt;link( @_ );
}

=head3 link C&lt;url&gt;, C&lt;text&gt;[, C&lt;%opts&gt;]

Specifies a link to C&lt;url&gt;, having C&lt;text&gt;. C&lt;%opts&gt; may contain:

=over

=item * C&lt;x&gt; - The x position of the link. Defaults to C&lt;x&gt;.

=item * C&lt;y&gt; - The y position of the link. Defaults to C&lt;y&gt;.

=item * C&lt;limit&gt; - The amount to "limit" the text. This will add an ellipis (...) a few characters from the end if the text length is greater than this numerical value. Defaults to 0, which is to mean "do not limit".

=item * C&lt;align&gt; - Which alignment you want for your text. The choices are 'left', 'center', and 'right'. Defaults to 'left'.

=item * C&lt;font&gt; - Specifies via font name, the font to use. This sets the current font.

=item * C&lt;font_size&gt; - Specifies the font size. This sets the current font size.

=item * C&lt;fill_color&gt; - Specifies the fill color. This sets the current fill color.

=item * C&lt;stroke_color&gt; - Specifies the stroke color. This sets the current stroke color.

=back

This method returns the width of the text.

=cut

sub link {
  my ($self, $url, $text, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $limit = $opts{'limit'} || 0;
  my $align = $opts{'align'} || 'left';
  my $text_obj = $self-&gt;_get_text_object_for_current_page( %opts );
  my @rect;
  my $annotation;

  $text = $self-&gt;_limit_text( $text, $limit ) if ($limit);

  @rect = $self-&gt;_render_text_at( $text_obj, $text, $x, $y, $align );
  $annotation = $self-&gt;current_page-&gt;annotation;

  $annotation-&gt;rect( @rect );
  $annotation-&gt;url( $url );

  # return text width
  return ($rect[2] - $rect[0]);
}

=head3 text C&lt;text&gt;[, C&lt;%opts&gt;]

Renders text onto the PDF.

=over

=item * C&lt;x&gt; - The x position of the link. Defaults to C&lt;x&gt;.

=item * C&lt;y&gt; - The y position of the link. Defaults to C&lt;y&gt;.

=item * C&lt;limit&gt; - The amount to "limit" the text. This will add an ellipis (...) a few characters from the end if the text length is greater than this numerical value. Defaults to 0, which is to mean "do not limit".

=item * C&lt;align&gt; - Which alignment you want for your text. The choices are 'left', 'center', and 'right'. Defaults to 'left'.

=item * C&lt;autoflow&gt; - Any value but 'off' will notify this method to use "autoflowing" heuristics to gracefully wrap your text over lines and pages. Useful for variable length text. Note that due to laziness, this option is mutually exclusive with C&lt;limit&gt;.

=item * C&lt;font&gt; - Specifies via font name, the font to use. This sets the current font.

=item * C&lt;font_size&gt; - Specifies the font size. This sets the current font size.

=item * C&lt;fill_color&gt; - Specifies the fill color. This sets the current fill color.

=item * C&lt;stroke_color&gt; - Specifies the stroke color. This sets the current stroke color.

=back

If C&lt;autoflow&gt; was B&lt;not&gt; specified, this method returns the width of the text in scalar context, the bounding box of the text in list context. In autoflow mode, this method returns nothing.

=cut

sub text {
  my ($self, $text, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $limit = $opts{'limit'} || 0;
  my $align = $opts{'align'} || 'left';
  my $autoflow = $opts{'autoflow'} || 'off';
  my $text_obj = $self-&gt;_get_text_object_for_current_page( %opts );
  my @words;

  # don't get fancy. just render the shit
  if (lc $autoflow eq 'off') {
    $text = $self-&gt;_limit_text( $text, $limit ) if ($limit);
    
    return $self-&gt;_render_text_at( $text_obj, $text, $x, $y, $align );
  }

  Carp::croak( "May not use limit when autoflow is on!" ) if ($limit);

  @words = split / /, $text;

  for (my $i = 0; $i &lt; scalar(@words); $i++) {
    my $word = $words[$i];

    if (($i + 1) &lt; scalar(@words)) {
      $word .= ' ';
    }

    if (($x + $text_obj-&gt;advancewidth( $word )) &gt; $self-&gt;effective_width) {
      $x = $self-&gt;margin_left;
      $y -= $self-&gt;line_height;
    }

    if ($self-&gt;_add_page_if_exceeds_bounds( $y )) {
      $x = $self-&gt;x;
      $y = $self-&gt;y;

      $text_obj = $self-&gt;_get_text_object_for_current_page( %opts );
    }

    $x += $self-&gt;_render_text_at( $text_obj, $word, $x, $y, $align );
  }
  
  $y -= $self-&gt;line_height;
  if (!$self-&gt;_add_page_if_exceeds_bounds( $y )) {  
    $self-&gt;y( $y );
  }
}

=head3 image C&lt;src&gt;[, C&lt;%opts&gt;]

Renders an image onto the PDF. The following image types are supported: JPG, TIFF, PNM, PNG, GIF, and PDF. Note that the module determines the image type by file extension.

=over

=item * C&lt;x&gt; - The x position of the link. Defaults to C&lt;x&gt;.

=item * C&lt;y&gt; - The y position of the link. Defaults to C&lt;y&gt;.

=item * C&lt;width&gt; - The width of the image. Defaults to 100.

=item * C&lt;height&gt; - The height of the image. Defaults to 100.

=item * C&lt;scale&gt; - Amount to scale the image. Defaults to 1. (only available for PDF types)

=back

=cut

sub image {
  my ($self, $src, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $width = $opts{'width'} || 100;
  my $height = $opts{'height'} || 100;
  my $scale = $opts{'scale'} || 1;
  my $image = $self-&gt;current_page-&gt;gfx;
  my $data;

  local $_ = $src;

  if (m/[.]jp(?:e)?g$/i) {
    $data = $self-&gt;pdf-&gt;image_jpeg( $_ );
  }
  elsif (m/[.]tif(?:f)?$/i) {
    $data = $self-&gt;pdf-&gt;image_tiff( $_ );
  }
  elsif (m/[.]pnm$/i) {
    $data = $self-&gt;pdf-&gt;image_pnm( $_ );
  }
  elsif (m/[.]png$/i) {
    $data = $self-&gt;pdf-&gt;image_png( $_ );
  }
  elsif (m/[.]gif$/i) {
    $data = $self-&gt;pdf-&gt;image_gif( $_ );
  }
  elsif (m/[.]pdf$/i) {
    my $p = PDF::API2-&gt;open( $_ );
    my $xo = $self-&gt;pdf-&gt;importPageIntoForm($p, 1);
    
    $self-&gt;current_page-&gt;gfx-&gt;formimage($xo, $x, $y, $scale);
    $self-&gt;x( $x );
    $self-&gt;y( $y );

    return;
  }
  else {
    Carp::croak("Cannot ascertain image type of $src\n");
  }

  $image-&gt;image($data, $x, $y, $width, $height);

  $self-&gt;x( $x + $width );
  $self-&gt;y( $y );
}

=head3 line [, C&lt;%opts&gt;]

Renders a line onto the PDF.

=over

=item * C&lt;x&gt; - The x position of the line. Defaults to C&lt;x&gt;.

=item * C&lt;y&gt; - The y position of the line. Defaults to C&lt;y&gt;.

=item * C&lt;to_x&gt; - The x position where to draw the line to.

=item * C&lt;to_y&gt; - The y position where to draw the line to.

=item * C&lt;fill_color&gt; - Specifies the fill color. This sets the current fill color. Defaults to C&lt;current_fill_color&gt;.

=item * C&lt;stroke_color&gt; - Specifies the stroke color. This sets the current stroke color. Defaults to C&lt;current_stroke_color&gt;.

=item * C&lt;width&gt; - Specifies the width of the line. Defaults to 0.5.

=back

=cut

sub line {
  my ($self, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $to_x = $opts{'to_x'};
  my $to_y = $opts{'to_y'};
  my $line = $self-&gt;current_page-&gt;gfx;

  $self-&gt;_standard_content_opts( $line, %opts );

  $line-&gt;move( $x, $y );
  $line-&gt;line( $to_x, $to_y );

  $self-&gt;_render_content( $line, %opts );

  $self-&gt;x( $to_x );
  $self-&gt;y( $to_y );
}

=head3 rect [, C&lt;%opts&gt;]

Renders a rectangle onto the PDF. Rectangles are usually drawn specifying two coordinates diagonal from each other. (5, 5) to (30, 30) for example, would produce a 25 x 25 square.

=over

=item * C&lt;x&gt; - The x position of the rect. Defaults to C&lt;x&gt;.

=item * C&lt;y&gt; - The y position of the rect. Defaults to C&lt;y&gt;.

=item * C&lt;to_x&gt; - The x position where to draw the rect to.

=item * C&lt;to_y&gt; - The y position where to draw the rect to.

=item * C&lt;stroke&gt; - A value of 'on', 'true', or 'yes' will enable the stroke. Defaults to 'on'.

=item * C&lt;fill&gt; - A value of 'on', 'true', or 'yes' will enable the fill. Defaults to 'off'.

=item * C&lt;fill_color&gt; - Specifies the fill color. This sets the current fill color. Defaults to C&lt;current_fill_color&gt;.

=item * C&lt;stroke_color&gt; - Specifies the stroke color. This sets the current stroke color. Defaults to C&lt;current_stroke_color&gt;.

=item * C&lt;width&gt; - Specifies the width of the line. Defaults to 0.5.

=back

=cut

sub rect {
  my ($self, %opts) = @_;
  my $x = $opts{'x'} || $self-&gt;x;
  my $y = $opts{'y'} || $self-&gt;y;
  my $to_x = $opts{'to_x'};
  my $to_y = $opts{'to_y'};
  my $stroke = $opts{'stroke'} || 'on';
  my $fill = $opts{'fill'} || 'off';
  my $rect = $self-&gt;current_page-&gt;gfx;

  $self-&gt;_standard_content_opts( $rect, %opts );

  $rect-&gt;rectxy( $x, $y, $to_x, $to_y );

  $self-&gt;_render_content( $rect, %opts );

  $self-&gt;x( $to_x );
  $self-&gt;y( $to_y );
}

# properties
# ================================================

=head1 PROPERTIES

The following properties are read/write, and may be used as $pdf-&gt;prop to read, $pdf-&gt;prop('val') to set.

=head2 header

Gets/sets the header callback.

=cut

sub header {
  my $self = shift;

  if (@_) {
    $self-&gt;{'header'} = shift;
  }

  return $self-&gt;{'header'};
}

=head2 footer

Gets/sets the footer callback.

=cut

sub footer {
  my $self = shift;

  if (@_) {
    $self-&gt;{'footer'} = shift;
  }

  return $self-&gt;{'footer'};
}

=head2 file

Gets/sets the file used to save the PDF. It's recommended that you B&lt;do not set this&gt;.

=cut

sub file {
  my $self = shift;

  if (@_) {
    $self-&gt;{'file'} = shift;
  }

  return $self-&gt;{'file'};
}

=head2 width

Gets/sets the width of the current page. It's recommended that you B&lt;do not set this&gt;.

=cut

sub width {
  my $self = shift;

  if (@_) {
    $self-&gt;{'width'} = shift;
    $self-&gt;_set_relative_values();
  }

  return $self-&gt;{'width'};
}

=head2 height

Gets/sets the height of the current page. It's recommended that you B&lt;do not set this&gt;.

=cut

sub height {
  my $self = shift;

  if (@_) {
    $self-&gt;{'height'} = shift;
    $self-&gt;_set_relative_values();
  }

  return $self-&gt;{'height'};
}

=head2 line_height

Gets/sets the default line height. This is used in most space layout methods.

=cut

sub line_height {
  my $self = shift;

  if (@_) {
    $self-&gt;{'line_height'} = shift;
  }

  return $self-&gt;{'line_height'};
}

=head2 margin_left

Gets/sets the left margin.

=cut

sub margin_left {
  my $self = shift;

  if (@_) {
    $self-&gt;{'margin_left'} = shift;
  }

  return $self-&gt;{'margin_left'};
}

=head2 margin_top

Gets/sets the top margin.

=cut

sub margin_top {
  my $self = shift;

  if (@_) {
    $self-&gt;{'margin_top'} = shift;
  }

  return $self-&gt;{'margin_top'};
}

=head2 margin_right

Gets/sets the right margin.

=cut

sub margin_right {
  my $self = shift;

  if (@_) {
    $self-&gt;{'margin_right'} = shift;
  }

  return $self-&gt;{'margin_right'};
}

=head2 margin_bottom

Gets/sets the bottom margin.

=cut

sub margin_bottom {
  my $self = shift;

  if (@_) {
    $self-&gt;{'margin_bottom'} = shift;
  }

  return $self-&gt;{'margin_bottom'};
}

=head2 width_right

Gets/sets the calculated value, C&lt;width&gt; - C&lt;margin_right&gt;

=cut

sub width_right {
  my $self = shift;

  if (@_) {
    $self-&gt;{'width_right'} = shift;
  }

  return $self-&gt;{'width_right'};
}

=head2 height_bottom

Gets/sets the calculated value, C&lt;height&gt; - C&lt;margin_bottom&gt;

=cut

sub height_bottom {
  my $self = shift;

  if (@_) {
    $self-&gt;{'height_bottom'} = shift;
  }

  return $self-&gt;{'height_bottom'};
}

=head2 effective_width

Gets/sets the calculated value, C&lt;width&gt; - (C&lt;margin_left&gt; + C&lt;margin_right&gt;)

=cut

sub effective_width {
  my $self = shift;

  if (@_) {
    $self-&gt;{'effective_width'} = shift;
  }

  return $self-&gt;{'effective_width'};
}

=head2 effective_height

Gets/sets the calculated value, C&lt;height&gt; - (C&lt;margin_top&gt; + C&lt;margin_bottom&gt;)

=cut

sub effective_height {
  my $self = shift;

  if (@_) {
    $self-&gt;{'effective_height'} = shift;
  }

  return $self-&gt;{'effective_height'};
}

=head2 current_page

Gets/sets the current page object. It's hard to find a good reason to set this, but it is possible to do so.

=cut

sub current_page {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_current_page'} = shift;
  }

  return $self-&gt;{'_current_page'};
}

=head2 pdf

Gets/sets the raw L&lt;PDF::API2&gt; object. This allows you great flexibility in your applications.

=cut

sub pdf {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_pdf'} = shift;
  }

  return $self-&gt;{'_pdf'};
}

=head2 fonts

Gets/sets the array of fonts we have been storing via the C&lt;add_font&gt; method.

=cut

sub fonts {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_fonts'} = shift;
  }

  return $self-&gt;{'_fonts'};
}

=head2 current_font

Gets/sets the current font.

=cut

sub current_font {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_current_font'} = shift;
    
    if (@_) {
      $self-&gt;current_font_size( shift );
    }
  }

  return $self-&gt;{'_current_font'};
}

=head2 current_font_size

Gets/sets the current font size.

=cut

sub current_font_size {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_current_font_size'} = shift;
  }

  return $self-&gt;{'_current_font_size'};
}

=head2 current_stroke_color

Gets/sets the current stroke color. Aliases for this method are C&lt;stroke_color&gt;, and C&lt;strokecolor&gt;

=cut

sub stroke_color {
  return current_stroke_color( @_ );
}

sub strokecolor {
  return current_stroke_color( @_ );
}

sub current_stroke_color {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_current_stroke_color'} = shift;
  }

  return $self-&gt;{'_current_stroke_color'};
}

=head2 current_fill_color

Gets/sets the current fill color. Aliases for this method are C&lt;fontcolor&gt;, C&lt;set_font_color&gt;, C&lt;font_color&gt;, C&lt;fillcolor&gt;, and C&lt;fill_color&gt;.

=cut

sub fontcolor {
  return current_fill_color( @_ );
}

sub set_font_color {
  return current_fill_color( @_ );
}

sub font_color {
  return current_fill_color( @_ );
}

sub fill_color {
  return current_fill_color( @_ );
}

sub fillcolor {
  return current_fill_color( @_ );
}

sub current_fill_color {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_current_fill_color'} = shift;
  }

  return $self-&gt;{'_current_fill_color'};
}

=head2 x

Gets/sets the current x position.

=cut

sub x {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_x'} = shift;
  }

  return $self-&gt;{'_x'};
}

=head2 y

Gets/sets the current y position.

=cut

sub y { # } sub emacs-hack {
  my $self = shift;

  if (@_) {
    $self-&gt;{'_y'} = shift;
  }

  return $self-&gt;{'_y'};
}

=head1 BUGS / FIXES

Please mail all bug reports, fixes, improvements, and suggestions to bugs -at- redtreesystems -dot- com.

=head1 SPONSERS AND LICENSE

This project was sponsered in part by deviateMEDIA - L&lt;http://deviatemedia.com&gt;. This project belongs to Red Tree Systems, LLC - L&lt;http://redtreesystems.com&gt;, but is placed into the public domain in the hopes that it will be educational and/or useful. deviateMEDIA and Red Tree Systems, LLC request only that each party are referenced, or this section kept intact with any modification of this module, or derivitive work thereof.

=head1 THANKS

Thanks to Bryan Krone for pointing out our obvious logisitical shortcomings.

=head1 SEE ALSO

L&lt;PDF::API2&gt;

There is an examples folder with this dist that should help you get started. You may contact pdfapi2simple -AT- redtreesystems _dot_ com for support on an individual or commercial basis.

=cut

1;
</pre></body></html>