use strict; use warnings; use LWP::Simple; use PDF::API2; use constant { JPG => 'jpg.jpg', PDF => 'pdf.pdf', URL => 'https://jpeg.org/images/jpeg-home.jpg', A4W => 595, A4H => 842, RES => 72, # image above is at 72 dpi }; -f JPG or is_success getstore URL, JPG or die; my $pdf = PDF::API2-> new; my $page = $pdf-> page; $page-> mediabox( 'A0' ); my $content = $page-> gfx; for my $row ( 0 .. 3 ) { for my $col ( 0 .. 3 ) { $content-> save; $content-> transform( -translate => [ A4W + $row * A4W, $col * A4H ], -rotate => 90, ); my $jpeg = $pdf-> image_jpeg( JPG ); my $w = 72 / RES * $jpeg-> width; my $h = 72 / RES * $jpeg-> height; $content-> translate(( A4H - $w )/2, ( A4W - $h )/2 ); $content-> image( $jpeg, 0, 0, 72 / RES ); $content-> restore; } } $pdf-> saveas( 'pdf.pdf' );