Skip to content

Instantly share code, notes, and snippets.

@trytone
Last active February 11, 2018 20:31
Show Gist options
  • Select an option

  • Save trytone/0ed0d6816f676e08f026c8e0b8632ab1 to your computer and use it in GitHub Desktop.

Select an option

Save trytone/0ed0d6816f676e08f026c8e0b8632ab1 to your computer and use it in GitHub Desktop.
Perl PDF::API scale
use PDF::API2;
my $filePath = 'example.pdf';
my $scale = 0.82; # Scale 82%
my ($x,$y) = (-13,113); # Coordinates
my $old_pdf = PDF::API2->open($filePath); # Open existing PDF file
my $pdf = PDF::API2->new(); # Open empty new PDF Document
my $page = $pdf->page();
my $gfx = $page->gfx();
my $xo = $pdf->importPageIntoForm($old_pdf, 1); # Return page view from content as Form
$gfx->formimage($xo, $x, $y, $scale); # Add our Form as Image at new blank page
$old_pdf->end; # Close handle to our PDF file ! IMPORTANT
$pdf->saveas($filePath);
$pdf->end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment