#!/usr/bin/perl

use PDF::API2;
use PDF::API2::Util;

BEGIN {
	eval " use GD; ";
	$hasGD = $@ ? 0 : 1;
}

$pdf=PDF::API2->new;

$f1=$pdf->corefont('Helvetica',1);
$f1->encode('latin1');


$f2=$pdf->corefont('Times-Roman',1);
$f2->encode('latin1');


foreach my $i (glob('*.jpg')) {
	$page = $pdf->page;
	$page->mediabox(595,842);
	$txt=$page->text;
	$txt->compress;

	$txt->translate(100,800);
	$txt->font($f1,30);
	$txt->text("image: $i");

	$gfx=$page->gfx;

	my $img=$pdf->image($i);
	
	$gfx->image($img,0,0);

	$gfx->image($img,200,200,72/150);

	$gfx->image($img,400,400,150,150);
}


if($hasGD) {
	foreach my $i (glob('*.png')) {
		$page = $pdf->page;
		$page->mediabox(595,842);
		$txt=$page->text;
		$txt->compress;

		$txt->translate(100,800);
		$txt->font($f1,30);
		$txt->text("image: $i");

		$gfx=$page->gfx;
		
		$gd=GD::Image->newFromPng($i);

		my $img=$pdf->image($gd);

		$gfx->image($img,0,0);

		$gfx->image($img,200,200,72/150);

		$gfx->image($img,400,400,150,150);
	}
}

$pdf->saveas("$0.pdf");

$pdf->end();

exit;

__END__
