欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

制作中文(繁简)的PDF

程序员文章站 2022-06-15 21:57:58
...

中文

有人还为无法用php_pdf做中文的pdf烦恼吧..
PHP_PDF套件在这边抓取,记得重新编译哦。用现成的会有MARK。
http://www.pdflib.com/pdflib/index.html

这是php_pdf配合Iconv转UTF-16做的简易制作中文PDF的范例。
此部份不包含排版。有空弟在写另外一个排版范例。


$pdf = pdf_new
();

pdf_open_file($pdf, "./test.pdf"
);
pdf_set_info($pdf, "Creator", iconv("BIG5","UTF-16","小企鹅"
));

pdf_begin_page($pdf, 595, 842
);
## BOOKMARK要用UTF-16的UNICODE哦
$Parent=pdf_add_bookmark($pdf, Iconv("BIG5","UTF-16","繁体中文"
));
pdf_add_bookmark($pdf, Iconv("BIG5","UTF-16","字体一"),$Parent
);
$font = PDF_findfont($pdf, "MHei-Medium", "ETen-B5-H", 0
);
PDF_setfont($pdf, $font, 14
);
pdf_show_xy($pdf, "海南搏浪岛浪搏南海", 50, 750
);
pdf_end_page($pdf
);


pdf_begin_page($pdf, 595, 842
);
pdf_add_bookmark($pdf, Iconv("BIG5","UTF-16","字体一"),$Parent
);
$font = PDF_findfont($pdf, "MSung-Light", "ETen-B5-H", 0
);
PDF_setfont($pdf, $font, 14
);
pdf_show_xy($pdf, "白沙明月夜月明沙白", 50, 750
);
pdf_end_page($pdf
);

pdf_begin_page($pdf, 595, 842
);
$Parent=pdf_add_bookmark($pdf, Iconv("BIG5","UTF-16","简体中文"
));
pdf_add_bookmark($pdf, Iconv("BIG5","UTF-16","字体一"),$Parent
);
$font = PDF_findfont($pdf, "STSong-Light", "GBK-EUC-H", 0
);
PDF_setfont($pdf, $font, 14
);
pdf_show_xy($pdf, "奻漆赻懂厄厄懂赻漆奻", 50, 750
);
pdf_show_xy($pdf, "笢刓甜菱豪豪菱甜刓笢", 50, 650
);
pdf_end_page($pdf
);

/*
中文 encoding 的部分
{ "GB-EUC-H", cc_simplified_chinese },
{ "GB-EUC-V", cc_simplified_chinese },
{ "GBpc-EUC-H", cc_simplified_chinese },
{ "GBpc-EUC-V", cc_simplified_chinese },
{ "GBK-EUC-H", cc_simplified_chinese },
{ "GBK-EUC-V", cc_simplified_chinese },
{ "UniGB-UCS2-H", cc_simplified_chinese },
{ "UniGB-UCS2-V", cc_simplified_chinese },

{ "B5pc-H", cc_traditional_chinese },
{ "B5pc-V", cc_traditional_chinese },
{ "ETen-B5-H", cc_traditional_chinese },
{ "ETen-B5-V", cc_traditional_chinese },
{ "ETenms-B5-H", cc_traditional_chinese },
{ "ETenms-B5-V", cc_traditional_chinese },
{ "CNS-EUC-H", cc_traditional_chinese },
{ "CNS-EUC-V", cc_traditional_chinese },
{ "UniCNS-UCS2-H", cc_traditional_chinese },
{ "UniCNS-UCS2-V", cc_traditional_chinese },
汉字型的部分

"MHei-Medium",
"MSung-Light",
"STSong-Light",

*/

pdf_close($pdf
);
pdf_delete($pdf
);
?>