#!/usr/bin/perl

use PDF::API2;
use Text::PDF::Utils;

$pdf=PDF::API2->new;

$sh=$pdf->shade;

	$sh->{ShadingType}=PDFNum(2);
	$sh->{ColorSpace}=PDFName('DeviceRGB');
	$sh->{Coords}=PDFArray(PDFNum(0),PDFNum(0),PDFNum(1),PDFNum(1));
	$sh->{Function}=PDFDict();
	$sh->{Function}->{FunctionType}=PDFNum(2);
	$sh->{Function}->{Domain}=PDFArray(PDFNum(0),PDFNum(1));
	$sh->{Function}->{C0}=PDFArray(PDFNum(1),PDFNum(1),PDFNum(1));
	$sh->{Function}->{C1}=PDFArray(PDFNum(0),PDFNum(0),PDFNum(1));
	$sh->{Function}->{N}=PDFNum(1);

$pt=$pdf->pattern(-type=>2,-matrix=>[500,0,0,500,0,0],-shading=>$sh);
$pt->{Type}=PDFName('Pattern');
$pt->{PatternType}=PDFNum(2);
$pt->{Matrix}=PDFArray(PDFNum(500),PDFNum(0),PDFNum(0),PDFNum(500),PDFNum(0),PDFNum(0));
$pt->{Shading}=$sh;

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

	$gfx=$page->gfx;
	$gfx->rect(0,0,500,500);
	$gfx->clip;
	$gfx->shade($sh,0,0,500,500);

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

	$gfx=$page->gfx;
 	$gfx->fillcolor($pt);
	$gfx->rect(0,0,500,500);
	$gfx->fill;

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

__END__
