PDF中文文件输出
来源:互联网 发布:mysql 查询一年的数据 编辑:程序博客网 时间:2024/06/06 05:14
pdf之一 中文输出
PDF文件格式以其安全可靠,易于交换,及保真度高而成为电子文档的标准。PDFlib是一套在国际上非常流行的在服务器端批量生成PDF文档的功能强大的软件包。国外许多政府,税务,银行,水电,邮电部门用其在线生成PDF格式的单据及报表。如何使用Acrobat 标准的简体中文字体
以上三种字体均支持以下几种编码(Encoding):UniGB-UCS2-H,UniGB-UCS2-V,UniGB-UTF16-H,UniGB-UTF16-V,GB-EUC-H,GB-EUC-V,GBpc-EUC-H,GBpc-EUC-V,GBK-EUC-H,GBK-EUC-V,GBKp-EUC-H,GBKp-EUC-V,GBK2K-H,及GBK2K-V。各编码的定义请见下表1.1:
表1.1
UniGB-UCS2-VUnicode (UCS-2) encoding for the Adobe-GB1 charactercollectionUniGB-UTF16-H
UniGB-UTF16-VUnicode (UTF-16BE) encoding for the Adobe-GB1 charactercollection.Contains mappings for all characters in the GB18030-2000character set.GB-EUC-H
GB-EUC-VMicrosoft Code Page 936 (charset 134), GB 2312-80 characterset, EUC-CN encodingGBpc-EUC-H
GBpc-EUC-VMacintosh, GB 2312-80 character set, EUC-CN encoding, ScriptManagercode 2GBK-EUC-H
GBK-EUC-VMicrosoft Code Page 936 (charset 134), GBK character set, GBKencodingGBKp-EUC-H
GBKp-EUC-VSame as GBK-EUC-H, but replaces half-width Latin characterswithproportional forms and maps code 0x24 to dollar ($) instead ofyuan (¥).GBK2K-H
GBK2K-VGB 18030-2000 character set, mixed 1-, 2-, and 4-byteencoding
编 码以-H结尾的,表示字体将会横向输出;以–V结尾的,表示字体将会纵向输出。以Uni开头的是Unicode类编码,如果你的输入字符串是Unicode,则应选择此类编码。以GB开头的是CP936类编码,如果你的输入字符串是Code Page 936,则应选择此类编码。
在PDFlib中若想调用以上其中一种字体,可直接用字体名和相应的编码:
int Font_CS;Font_CS = PDF_load_font(p, " STSong-Light ", 0, " ", " UniGB-UTF16-H");不久,你们将会发现,字体与编码间可有非常多的组合,而PDFlib的字体功能(function)并不支持所有的组合。最为保险的组合是PDFlib自带三种字体与Unicode类编码的组合。
下面是一个使用PDFlib自带字体及编码的C 源程序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pdflib.h"
int main(void)
{
*p = NULL;
inti = 0, j = 0, Left = 50, Top = 800;
intFont_E = 0, Font_CS = 0;
charTextUnicode[] = "\x80\x7B\x53\x4F\x2D\x4E\x87\x65"; char TextCp936[] = "\xBC\xF2\xCC\xE5\xD6\xD0\xCE\xC4";
charEncodingName[100];
static const char *ChineseFont[] = {"STSong-Light","AdobeSongStd-Light-Acro", "STSongStd-Light-Acro", };
static const char *Encoding[] =
{ "UniGB-UCS2-H",
"UniGB-UCS2-V",
"UniGB-UTF16-H",
"UniGB-UTF16-V",
"GB-EUC-H",
"GB-EUC-V",
"GBpc-EUC-H",
"GBpc-EUC-V",
"GBK-EUC-H",
"GBK-EUC-V",
"GBKp-EUC-H",
"GBKp-EUC-V",
"GBK2K-H",
"GBK2K-V", };
const intfsize = sizeof ChineseFont / sizeof (char *);
const intesize = sizeof Encoding / sizeof (char *);
if ((p = PDF_new()) == (PDF *) 0)
{ printf("Couldn't create PDFlib object (out of memory)!\n");
return(2); }
PDF_TRY(p)
{ if (PDF_begin_document(p, "pdflib_cs1.pdf", 0, "") == -1) { printf("Error: %s\n", PDF_get_errmsg(p)); return(2); }
PDF_set_info(p, "Creator", "pdflib_cs1.c");
PDF_set_info(p, "Author", "bowriver2001@yahoo.ca");
PDF_set_info(p, "Title", "Output Chinese Simplify with PDFlib builtin font");
Font_E = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", "");
for (i = 0; i < fsize; i++)
{
Top = 800;
PDF_begin_page_ext(p, a4_width, a4_height, "");
PDF_setfont(p, Font_E, 24);
PDF_show_xy(p, ChineseFont[i] , Left + 50,Top); Top -= 30;
for (j = 0; j < esize; j++)
{ Font_CS = PDF_load_font(p, ChineseFont[i], 0, Encoding[j], ""); PDF_setfont(p, Font_E, 12);
strcpy(EncodingName, "");
strcat(EncodingName,Encoding[j]);
strcat(EncodingName,":");
PDF_show_xy(p, EncodingName , Left,Top);
PDF_setfont(p, Font_CS, 12);
if (strstr(Encoding[j], "-H") != NULL)
{
Top -= 15; } if (strstr(Encoding[j], "UniGB") != NULL) { PDF_show_xy2(p, TextUnicode, 8, Left,Top); } else
{ PDF_show_xy2(p, TextCp936, 8, Left,Top); }
if (strstr(Encoding[j], "-H") != NULL)
{ Top -= 25; } else { Top -= 65;
}
}
PDF_end_page_ext(p, ""); }
PDF_end_document(p, "");
}
PDF_CATCH(p)
{ printf("PDFlib exception occurred in pdflib_cs1 sample:\n"); printf("[%d] %s: %s\n", PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p)); PDF_delete(p); return(2); }
PDF_delete(p);
return 0;
}
- PDF中文文件输出
- pdflib输出中文pdf
- 使用iText输出PDF文件
- Fastreport3.14的中文PDF输出
- SAS9中输出中文PDF文档
- 如何在R中输出中文PDF
- Rmarkdown输出PDF的中文支持问题解决
- PDFLIB打印PDF,能输出中文英文
- R语言pdf输出中文乱码处理
- 记录Jupyter Notebook中文pdf输出过程
- HTML导出PDF中文文件
- jpivot 中输出 pdf打印中文、excel导出中文方法
- JSP读取PDF文件页面输出
- 输出pdf文件的一个简单方法
- 英文版PDF不能显示中文PDF文件的解决方法
- 用itext导出pdf文件,包含中文
- Ubuntu 读pdf文件中文乱码解决方案
- linux下pdf文件中文乱码解决方案
- JPA入门例子(采用JPA的hibernate实现版本)
- 2140 DotA高手
- 【软件测试 1】如何写(好)测试用例 --网络整理
- 没标题
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- PDF中文文件输出
- 文本框里文字悬浮触发事件
- SQL 2012 PowerPivot for Excel 数据源初始化失败解决方法
- vs2010 c++快捷键精选
- Java解析XML汇总(DOM/SAX/JDOM/DOM4j/XPath)
- Spring @Transactional 声明式事务管理 getCurrentSession
- Oracle 9i RMAN创建DataGuard
- lucene&solr大盘点
- 程序员技术练级攻略