smlxp 发表于 2006-07-30 15:17

PDF正常输出中文,代码贴出

<?php
/* $Id: hello.php,v 1.14 2004/05/23 11:34:03 tm Exp $
*
* PDFlib client: hello example in PHP
*/

$p = PDF_new();

/*open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p, "", "") == 0) {
    die("Error: " . PDF_get_errmsg($p));
}

/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter($p, "hypertextencoding", "winansi");
PDF_set_parameter($p, "SearchPath", "C:\\WINNT\\Fonts");

PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)!");


PDF_begin_page_ext($p, 595, 842, "");

//$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
$font = PDF_load_font($p, "AdobeSongStd-Light-Acro", "UniGB-UTF16-H", "");
//PDF_setfont(p, font, 24);

//UniGB-UTF16-H    STSong-Light

PDF_setfont($p, $font, 24.0);
PDF_set_text_pos($p, 50, 700);
$text = iconv("gb2312","UTF-16","离离原上草一岁一枯荣");
PDF_show($p, $text);
$text1 = iconv("gb2312","utf-16","(says PHP)");
PDF_continue_text($p, $text1);
PDF_end_page_ext($p, "");

PDF_end_document($p, "");

$buf = PDF_get_buffer($p);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;

PDF_delete($p);
?>

困扰了一段时间,今天试成了!以上代码在用户装好Pdflib和Iconv前提下可以运行成功!

achieverain 发表于 2006-07-31 14:02

支持一下。唯一遗憾的就是免费版的pdflib那个水印太讨厌了

alinker 发表于 2006-07-31 14:06

有水印?

nff 发表于 2006-07-31 15:07

PDF正常输出中文解决方法

不好意思,以前做过,现在才找到.
见附件!

nff 发表于 2006-07-31 15:11

回复 4楼 nff 的帖子

将其中chinese.php 的代码加入到 FPDF类中合适的地方,然后仿照ex.php调用即可!

achieverain 发表于 2006-07-31 16:25

原帖由 nff 于 2006-7-31 15:07 发表
不好意思,以前做过,现在才找到.
见附件!

这个是繁体的解决方案,应该是用的台湾那个朋友的文件。请问有gb2312的解决方案吗?

nff 发表于 2006-07-31 16:59

回复 6楼 achieverain 的帖子

只有这一个!我以前用他也可以生成简体中文的.

achieverain 发表于 2006-07-31 21:33

原帖由 nff 于 2006-7-31 16:59 发表
只有这一个!我以前用他也可以生成简体中文的.

能给个gb2312的demo吗?我用过,但是简体的老是乱码。。。:em06:

nff 发表于 2006-08-01 08:57

回复 8楼 achieverain 的帖子

以前确实用它生成了简体中文的配置文件,现在忘记是怎么配置的了.

ttl_web 发表于 2008-09-29 10:27

短路

首先向原作者说声不好意识了

因为业务只有简体需要,不需要每次打开pdf时更新升级adobe的繁体,
所以屏蔽chinese.php中Big5字体函数,修改了ex.php部分内容
页: [1] 2
查看完整版本: PDF正常输出中文,代码贴出