try {
wostringstream optlist;
optlist.str(L"");
PDFlib p;
p.set_option(L"errorpolicy=return");
p.set_option(optlist.str());
if (p.begin_document(L"test.pdf", L"") == -1) {
return 2;
}
p.set_info(L"Creator", L"PDFlib starter sample");
p.set_info(L"Title", L"headertext");
int font = p.load_font(L"Times-Bold", L"winansi", L"");
if (font == -1) {
return(2);
}
optlist.str(L"");
optlist << L"fittextline={position=center font=" << font
<< L" fontsize=14} colspan=" << 5;
int tbl = -1;
int row = 1;
tbl = p.add_table_cell(tbl, 1, row, L"test", optlist.str());
if (tbl == -1) {
wcerr << L"Error: " << p.get_errmsg() << endl;
return 2;
}
int col = 0;
for (row++; row <= 100; row++) {
for (col = 1; col <= 5; col++) {
wostringstream num;
num << L"Col " << col << L"/Row " << row;
optlist.str(L"");
optlist << L"colwidth=20% fittextline={font=" << font
<< L" fontsize=10}";
tbl = p.add_table_cell(tbl, col, row, num.str(), optlist.str());
}
}
wstring result;
do {
p.begin_page_ext(0, 0, L"width=a4.width height=a4.height");
result = p.fit_table(tbl, 50, 50, 550, 800,
L"rowheightdefault=auto "
L"fill={ {area=rowodd fillcolor={gray 0.9}}} "
L"stroke={ {line=other}}");
if (result == L"_error") {
wcerr << L"Couldn't place table: " << p.get_errmsg() << endl;
return 2;
}
p.end_page_ext(L"");
} while (result == L"_boxfull");
if (result != L"_stop") {
if (result == L"_error") {
wcerr << L"Error when placing table: " << p.get_errmsg()
<< endl;
return 2;
}
else {
wcerr << L"User return found in Table" << endl;
return 2;
}
}
p.delete_table(tbl, L"");
p.end_document(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;
}
效果如下: