Saturday, April 25, 2009

perl pdf encode utf8 and shift_jis(japanese font)

#!/usr/bin/perl -w
use strict;
use PDF::API2;
my $pdf = PDF::API2->new;
$pdf = PDF::API2->open('/tmp/old.pdf');
my $page = $pdf->openpage(1);
my $gfx = $page->gfx;
#my $jfs = $pdf->cjkfont( 'KozGo', -encode=>'utf8' );
my $jfs = $pdf->cjkfont( 'KozGo', -encode=>'shiftjis' );
my $text = "T03 2007/1/23 どんなかんじでしょうかね";
$gfx->textlabel(30, 800, $jfs, 20, $text, -color=>'red');
$pdf->saveas("new_file.pdf");