pdflib的使用代码
从PDFlib-CMap-1.0.zip解压缩出CMap文件,将UniGB-UCS2-H文件拷贝到DLL文件目录,使用下面的示例代码:
#include "PDFLib.hpp"
#pragma comment(lib, "PDFLib.lib")
PDF *pdf = PDF_new();
// 打开文档
if (PDF_begin_document(pdf, strNamePDF.c_str(), 0, "") == -1)
{
printf("Error: %sn", PDF_get_errmsg(pdf));
return(0);
}
PDF_set_parameter(pdf, "searchpath", "include/pdflib/PDFlib-CMap-1.0/resource/cmap");//设置字体参数的
// 设置文档信息
PDF_set_info(pdf,"Creator", "PDF Creator");
PDF_set_info(pdf,"Author", "Neware");
PDF_set_info(pdf,"Title", "Convert to PDF");
PDF_set_info(pdf,"Subject", "PDF Creator");
PDF_set_info(pdf,"Keywords", "vckbase.com");
PDF_begin_page_ext(pdf,a4_width, a4_height,"");// 开始A4页面
nHeight = a4_height;//当前高度
int font_song = PDF_load_font(pdf,"STSong-Light",0, "GB-EUC-H","");
PDF_setfont(pdf,font_song, 6);// 设置字体为6号宋体
// 设置起始点
nHeight -= 50;
PDF_set_text_pos(pdf,50,nHeight);
// 设置颜色为蓝色
PDF_setcolor(pdf,"fill", "rgb", 0, 0, 1, 0);
static const char *DFTitle[] = {"数据序号","工步号","工步类型","工作类型","工步时间","电压","电流","内阻","温度","充电容量","充电能量","放电容量","放电能量","绝对时间"};
for(int i = 0; i < 14 ; i++)
{//表头
PDF_set_text_pos(pdf,38*i, nHeight);
PDF_show(pdf,DFTitle[i]);
}
// 画两根绿线
nHeight -= 8;
PDF_setcolor(pdf,"stroke", "rgb", 0.24f, 0.51f, 0.047f, 0);
PDF_moveto(pdf,0,nHeight);
PDF_lineto(pdf,a4_width,nHeight);
nHeight -= 2;
PDF_moveto(pdf,0,nHeight);
PDF_lineto(pdf,a4_width,nHeight);
PDF_stroke(pdf);
PDF_end_page_ext(pdf, "");// 结束本页
PDF_end_document(pdf, "");// 关闭PDF文件
PDF_delete(pdf); 原文来自http://www.kindeditor.com/doc/3710