#!/usr/bin/perl

use PDF::API2;

if(-f $ARGV[0]) {
	$pdf=PDF::API2->open($ARGV[0]);
} else {
	$pdf=PDF::API2->new;
}

delete $pdf->{forcecompress};

$i=0;

foreach $fn (glob("*.pfb")) {

	$ff=$fn;
	$ff=~s/\.pfb$/.afm/;

	$font=$pdf->psfont($fn,$ff);

	foreach $fe (qw(
		latin1
	)) {

		$page = $pdf->page;
		$page->mediabox(595,842);
		$txt=$page->text;

		$fen=$font->clone($fe);
		$fen->encode($fe);

		$txt=$page->text;
		$txt->translate(100,700);
		$txt->font($fen,50);
		$txt->text('Hello World !');

		foreach $x (0..15) {
			foreach $y (0..15) {
				$txt->translate(50+(33*$x),50+(33*$y));
				$txt->text(chr($y*16+$x));
			}
		}

	}
}

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

$pdf=PDF::API2->open("$0.pdf");
$pdf2=PDF::API2->new;
delete $pdf2->{forcecompress};
$pdf2->importpage($pdf,1);
$page=$pdf2->clonepage(1);

$font=$pdf2->corefont('Helvetica-Bold',1);

$txt=$page->text;

$txt->translate(50,800);
$txt->font($font,10);
$txt->text('Updated World !');

foreach $fn (glob("*.ttf")) {


	foreach $fe (qw(
		latin1
	)) {

		$page = $pdf->page;
		$page->mediabox(595,842);
		$txt=$page->text;

		$font=$pdf2->ttfont($fn, -encode=>$fe);

		$txt=$page->text;
		$txt->translate(100,700);
		$txt->font($font,50);
		$txt->text('Hello World !');
		$txt->font($font,20);

		foreach $x (0..15) {
			foreach $y (0..15) {
				$txt->translate(50+(33*$x),50+(33*$y));
				$txt->text(chr($y*16+$x));
			}
		}

	}
}


$pdf2->saveas("$0.2.pdf");
$pdf->end();
$pdf2->end();

$pdf=PDF::API2->open("$0.2.pdf");
$page=$pdf->clonepage(1);
delete $pdf->{forcecompress};

$font=$pdf->corefont('Helvetica-Bold',1);

$txt=$page->text;

$txt->translate(50,810);
$txt->font($font,10);
$txt->text('Updated2 World !');

$page->update;

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

$pdf->end();

exit;

__END__
