PDFlib使用(c++)

发布时间:2025-12-09 20:12:33 浏览次数:3

vc6.0使用pdflib操作pdf文件

PDFlib库下载

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;//数字123wchar_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常用函数手册:

PDFlib常用函数


该博客意在记笔记,纯属为了以后使用方便!!! 

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477