在利用pdflib生成PDF中,加载完图像后,打开PDF文件显示打开文档过程中发生错误,文件已损坏且无法修复

w136111526 2015-07-21 02:25:44
#include <iostream>

#include "pdflib.hpp"

using namespace std;
using namespace pdflib;

int
main(void)
{
try {
/* This is where the data files are. Adjust as necessary. */
const wstring searchpath = L"../data";

PDFlib p;
const wstring imagefile = L"nesrin.jpg";
int image;

wostringstream optlist;

// This means we must check return values of load_font() etc.
p.set_option(L"errorpolicy=return");

// Set the search path for fonts and PDF files
optlist.str(L"");
optlist << L"searchpath={{" << searchpath << L"}}";
p.set_option(optlist.str());

if (p.begin_document(L"starter_basic.pdf", L"") == -1) {
wcerr << L"Error: " << p.get_errmsg() << endl;
return 2;
}

p.set_info(L"Creator", L"PDFlib starter sample");
p.set_info(L"Title", L"starter_basic");

image = p.load_image(L"auto", imagefile, L"");

if (image == -1) {
wcerr << L"Error: " << p.get_errmsg() << endl;
return 2;
}

p.begin_page_ext(595, 842, L"");

optlist.str(L"");
optlist.str(L"fontname={LinLibertine_R} encoding=unicode embedding fontsize=24");

p.fit_textline(L"en: Hello!", 50, 700, optlist.str());

p.fit_image(image, 0.0, 0.0, L"scale=0.25");
p.end_page_ext(L"");

/* Page 2 */
p.begin_page_ext(595, 842, L"");

/* red rectangle */
p.setcolor(L"fill", L"rgb", 1.0, 0.0, 0.0, 0.0);
p.rect(200, 200, 250, 150);
p.fill();

/* blue circle */
p.setcolor(L"fill", L"rgb", 0.0, 0.0, 1.0, 0.0);
p.arc(400, 600, 100, 0, 360);
p.fill();

/* thick gray line */
p.setcolor(L"stroke", L"gray", 0.5, 0.0, 0.0, 0.0);
p.setlinewidth(10);
p.moveto(100, 500);
p.lineto(300, 700);
p.stroke();

p.fit_image(image, 150.0, 25.0, L"scale=0.25");
p.end_page_ext(L"");

catch (PDFlib::Exception &ex) {
wcerr << L"PDFlib exception occurred:" << endl
<< L"[" << ex.get_errnum() << L"] " << ex.get_apiname()
<< L": " << ex.get_errmsg() << endl;
return 2;
}

return 0;
}
...全文
1095 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
感动自己 2015-10-08
  • 打赏
  • 举报
回复
楼主 生成pdf 是自动打开 还是手动 打开

1,277

社区成员

发帖
与我相关
我的任务
社区描述
软件工程 CVS/SVN
社区管理员
  • 版本控制社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧