vc6.0使用pdflib操作pdf文件
1.将pdflib.dll放到Debug文件中
2.将pdflib.hpp、pdflib.h、pdflib.lib放到项目文件夹中
3.引入头文件
#include "pdflib.hpp"
#pragma comment(lib,"pdflib.lib")
using namespace pdflib;
4.创建PDFlib对象
PDFlib p;
wostringstream buf;
const wstring searchpath = L"../data";
const wstring fontopt1 = L"fontname=宋体 fontsize=24";//设置字体
p.set_option(L"errorpolicy=return");
buf.str(L"");
buf << L"searchpath={{" << searchpath << L"}}";
p.set_option(buf.str());
p.begin_document(L"xxx.pdf", L"");
5.创建一个新的页面
p.begin_page_ext(0, 0, L"width=a4.width height=a4.height");
6.写入一行文字(要写入的文字,x坐标,y坐标,字体)
p.fit_textline(L" 123 ", 20, 800, fontopt1);
7.画一条线
p.setlinewidth(2);//设置线条粗细
p.setcolor(L"stroke", L"rgb", 0.0f, 0.0f, 0.0f, 1.0f);//设置线条颜色
p.moveto(10, 808);p.lineto(590, 808);p.stroke();//画线(10,808)-(590,808)
8.写入数字
wstringstream str_date1;
str_date1<<fixed<<setprecision(2)<<123;//数字123
wchar_t date1[10];
str_date1>>date1;
p.fit_textline(date1, 200, 780, fontopt2);//(1,2)
9.结束
p.end_page_ext(L"");
p.end_document(L"");
PDFlib常用函数手册:
该博客意在记笔记,纯属为了以后使用方便!!!