PHPでShift_JISのPDFファイルを生成する方法です。 このソースコードではEUC-JPのファイルを前提としています。 mb_convert_encoding関数を利用してEUC-JPをShift_JISに変換しています。 PDFlibのload_fontメソッドでフォントにShift_JIS(cp932)エンコードでの変換を指定しています。
$p->load_font("HeiseiKakuGo-W5", "90ms-RKSJ-H", "");
<?php define('PATH_CMaps', '/usr/local/pdflib7/resource/cmap'); try { $p = new PDFlib(); $p->set_parameter("SearchPath", PATH_CMaps); $p->set_parameter("errorpolicy", "return"); $p->begin_document("", ""); $p->set_info("Creator", "hello_sjis.php"); $p->set_info("Author", "Opentype co.ltd,"); $p->set_info("Title", "Hello world (PHP)!"); $p->begin_page_ext(595, 842, ""); // cp932(sjis)エンコードに対応したフォント呼び出し $font = $p->load_font("HeiseiKakuGo-W5", "90ms-RKSJ-H", ""); if ($font == 0) { die("Error: " . $p->get_errmsg()); } $p->setfont($font, 48.0); $p->set_text_pos(50, 700); // このファイルが文字コードEUC-JPでSJISのファイルに変換するという前提 $hello = mb_convert_encoding("こんにちは世界!", "SJIS", "EUC-JP"); $str = mb_convert_encoding("(PHPによる出力)", "SJIS", "EUC-JP"); $p->show($hello); $p->continue_text($str); $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello_sjis.pdf"); print $buf; } catch (PDFlibException $e) { die("PDFlib exception occurred in hello sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); } catch (Exception $e) { die($e); } $p = 0;
このPDFを見る
codeなにがし::Shift_JISのPDFファイルを生成するには