首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 
设为首页
加入收藏
联系我们
热门关键字: .net应用  操作系统  Dreamweaver  WinRAR  网络推广
高级搜索
您当前的位置: 主页>PHP专区>PHP教学>PHP实现PDF正常输出中文的代码
PHP实现PDF正常输出中文的代码
来源: 发布时间:2007-12-09 发布人: 浏览: 人次   字体: [ ]  
PHP实现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前提下可以运行成功!


相 关 文 章   发布商链接
·PHP中Zend Cache用法的小例子
·为什么PHP不适合于比小型业余网站更...
·fckeditor在php环境中的配置及其使用...
·实例介绍搭建PHP5和SQL Server 2005...
·用PHP操纵Oracle的LOB类型的数据
·使用php读取xml数据的示例
·PHP实现明天时间的计算
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·实例介绍搭建PHP5和SQL Serve...
·fckeditor在php环境中的配置...
·为什么PHP不适合于比小型业余
·PHP中Zend Cache用法的小例子
·PHP实现明天时间的计算
·使用php读取xml数据的示例
·用PHP操纵Oracle的LOB类型的...
热 门 文 章
·fckeditor在php环境中的配置...
·PHP实现明天时间的计算
·使用php读取xml数据的示例
·为什么PHP不适合于比小型业余...
·用PHP操纵Oracle的LOB类型的...
·PHP中Zend Cache用法的小例子
·实例介绍搭建PHP5和SQL Serve...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .