PDFãperlããåçã«ä½æããPDFJã¨ããããªã¼ã®ã½ããã¦ã§ã¢ã触ã£ã¦ã¿ãã
http://hp1.jonex.ne.jp/~nakajima.yasushi/
UTF8ã«ã対å¿ãã¦ããã¨ãããã¨ã§ãä»åã¯UTF8ã§ä½æããã¡ããPerlã®ã½ã¼ã¹ã¯UTF8ã§ä¿åãã¦ã¾ãã
PDFJã®è¯ãã¨ããã¯ãåçã«æ ç·ä»ãã®ããã¯ã¹ã®é«ããå¤ããããæ¹ãã¼ã¸ã§ãããããã¨ããã
ã¾ãã¯ãã½ã¼ã¹ããã¦ã³ãã¼ããã¦ãä¾åããTeX::Hyphenã¢ã¸ã¥ã¼ã«ãå ¥ããå¾ã«ãã¤ã³ã¹ãã¼ã«
perl -MCPAN -e shell install TeX::Hyphen PDFJã®ZIPãå±éãããã£ã¬ã¯ããªã«ç§»åå¾ãä¸è¨ãå®è¡ perl Makefile.pl make make install
ã¾ãã¯ãã¹ã¿ã³ãã¢ãã¼ã³ã§åãããã°ã©ã ãä½ããå®è¡ããã¨ãhoge.pdfãåä¸ãã£ã¬ã¯ããªã«åºæ¥ãã¨ããããã°ã©ã ã
#!/usr/bin/perl -w use utf8; use strict; use PDFJ qw[UTF8]; ############################################# my $pdf_version = 1.3; my $paper_width = 595; my $paper_height = 842; ############################################# my $doc = PDFJ::Doc->new($pdf_version, $paper_width, $paper_height); my $font_mincho = $doc->new_font('Ryumin-Light', 'UniJIS-UCS2-HW-H', 'Times-Roman'); my $page = $doc->new_page; my $text = Text("TESTãã¹ãããããããããããããããããããããããããããããããããããããããããããããããããããããããã", TStyle(font => $font_mincho, fontsize => 16)); $text->show($page, 72, 523, 'tl'); $doc->print("hoge.pdf");
ãããå®è¡ããã¨ãåä¸ãã£ã¬ã¯ããªã«PDFãçæãããããããPDFã®ãã¥ã¼ã¯ã§è¦ã¦ã¿ãã¨ãã¡ããã¨è¦ããããã ãããããããããããããããå¤ããã¦ã¯ã¿ã ãã¦ãã¾ã£ã¦ããï¼ããã¯æ¬¡ã§è§£æ±ºãã¾ãï¼
new_font()ã®ä¸ã®ç¬¬2å¼æ°ã§ã¨ã³ã³ã¼ãã£ã³ã°ãæå®ããã®ã§ãããUTF8ã¯UniJIS-UCS2-HW-Hãæå®ãã¨ããªãã¨ãã¾ãåããªãã
ã§ããããCGIã«ãã¦ãã¢ã¯ã»ã¹ãããPDFããã¦ã³ãã¼ãåºæ¥ãããã«å¤æ´ãããã¦ã¯ã¿ã ãã¦ãã¾ã£ãæåããã¾ãæ¹è¡ãããããã«å¤æ´ã
#!/usr/bin/perl -w use utf8; use strict; use PDFJ qw[UTF8]; ############################################# my $pdf_version = 1.3; my $paper_width = 595; my $paper_height = 842; ############################################# my $doc = PDFJ::Doc->new($pdf_version, $paper_width, $paper_height); my $font_mincho = $doc->new_font('Ryumin-Light', 'UniJIS-UCS2-HW-H', 'Times-Roman'); my $page = $doc->new_page; my $text = Text("TESTãã¹ãããããããããããããããããããããããããããããããããããããããããããããããããããããããã", TStyle(font => $font_mincho, fontsize => 16)); my $parag = Paragraph($text, PStyle(size=>200, linefeed => '150%', align => 'e')); #withboxãsã«ããã¨æ ç·è¡¨ç¤º my $block = Block('V', $parag, BStyle(withbox => 's', padding => '5')); #ãã¼ã¸ã®å·¦ãã50px, ä¸ãã840pxã®ä½ç½®ã«è¡¨ç¤º $block->show($page,50,840); print "Content-type: application/pdf\n\n"; #æ¨æºåºåãããå ´å㯠- ãæå®ããå¿ è¦ãã $doc->print("-"); exit;
ä»åã¯ãããã¹ããParagraphã«å ¥ãã¦ãããããããã¯ã«å ¥ãã¦ãããã¯ã§æ ç·è¡¨ç¤ºããã¦ã¾ãããã®ããã«ãå¤æ®µéã«ç©ã¿éãã¦ãæå¾ã«show()ã¡ã½ããã§æå®ä½ç½®ã«è¡¨ç¤ºããã¾ãã
Paragraphã¡ã½ããã®ä¸ã®PStyleã§sizeãæå®ããæ¨ªå¹ ã決ãããã®ãµã¤ãºã§èªåçã«æåãæãè¿ãã«ãªãã®ã§ãã¯ã¿ã ãã¦ããæåãç¡äºè¡¨ç¤ºããã¾ããã
æå¾ã«ãContent-type: application/pdfã®å¾ã«å®éã®PDFãã¼ã¿ãåºåããã¾ããæ¨æºåºåãããå ´åã¯ãprintã¡ã½ããã§print("-")ã¨ãã¾ããããã§cgiã«ã¢ã¯ã»ã¹ããã°PDFã®ãã¦ã³ãã¼ãã表示ãå¯è½!!