電線の画像

Pointgets.net

写真やサンプルプログラムなど、日々の気になった出来事をメモしてる個人的なブログです。

PDF::Tableで日本語を生成

PerlモジュールのPDF::Tableを使用して、日本語を出力しました。

#!/opt/local/bin/perl
 
use strict;
use warnings;
use utf8;
use PDF::API2;
use PDF::Table;
 
my $pdf = PDF::API2 -> new();
my $page = $pdf -> page();
$page -> mediabox("A4");
my $table = PDF::Table -> new();
 
my $data = [
	["ん","わ","ら","や","ま","は","な","た","さ","か","あ"],
	["","ゐ","り","","み","ひ","に","ち","し","き","い"],
	["","","る","ゆ","む","ふ","ぬ","つ","す","く","う"],
	["","ゑ","れ","","め","へ","ね","て","せ","け","え"],
	["","を","ろ","よ","も","ほ","の","と","そ","こ","お"]
];
 
$table -> table(
	$pdf,
	$page,
	$data,
	x => 50,
	w => 495,
	start_y => 750,
	next_y => 700,
	start_h => 300,
	next_h => 500,
	font => $pdf -> cjkfont("KozGo",-encoding => "utf8"),
	font_size => 28,
	font_color => "#000000",
	justify => "center",
	padding_top => 10,
	padding_bottom => 18
);
 
print "Content-type: application/pdf; charset=utf-8\n\n";
binmode(STDOUT);
print $pdf -> stringify();
 
exit;

サンプルコードです。

出力結果です。

スポンサードリンク
スポンサードリンク