📄 pdflib.cpp
字号:
/*---------------------------------------------------------------------------*
| PDFlib - A library for generating PDF on the fly |
+---------------------------------------------------------------------------+
| Copyright (c) 1997-2005 Thomas Merz and PDFlib GmbH. All rights reserved. |
+---------------------------------------------------------------------------+
| |
| This software is subject to the PDFlib license. It is NOT in the |
| public domain. Extended versions and commercial licenses are |
| available, please check http://www.pdflib.com. |
| |
*---------------------------------------------------------------------------*/
// $Id: pdflib.cpp,v 1.54.2.5 2005/06/15 14:42:39 rjs Exp $
//
// in sync with pdflib.h 1.232
//
// Implementation of C++ wrapper for PDFlib
//
//
#include "pdflib.hpp"
#define CHAR(s) (s).c_str()
#define LEN(s) ((int) (s).size())
PDFlib::Exception::Exception(string errmsg, int errnum, string apiname,
void *opaque)
: m_errmsg(errmsg),
m_errnum(errnum),
m_apiname(apiname),
m_opaque(opaque)
{ }
string PDFlib::Exception::get_errmsg() { return m_errmsg; }
int PDFlib::Exception::get_errnum() { return m_errnum; }
string PDFlib::Exception::get_apiname() { return m_apiname; }
const void * PDFlib::Exception::get_opaque() { return m_opaque; }
#define PDFCPP_TRY PDF_TRY(p)
#define PDFCPP_CATCH \
PDF_CATCH(p) {\
throw Exception(PDF_get_errmsg(p), PDF_get_errnum(p),\
PDF_get_apiname(p), PDF_get_opaque(p));\
}
PDFlib::PDFlib(
allocproc_t allocproc,
reallocproc_t reallocproc,
freeproc_t freeproc,
void *opaque) throw(PDFlib::Exception)
{
m_PDFlib_api = ::PDF_get_api();
if (m_PDFlib_api->sizeof_PDFlib_api != sizeof(PDFlib_api) ||
m_PDFlib_api->major != PDFLIB_MAJORVERSION ||
m_PDFlib_api->minor != PDFLIB_MINORVERSION) {
throw Exception("loaded wrong version of PDFlib library", 0,
"pdflib.cpp", opaque);
}
m_PDFlib_api->PDF_boot();
p = m_PDFlib_api->PDF_new2(NULL, allocproc, reallocproc, freeproc, opaque);
if (p == (PDF *)0) {
throw Exception("No memory for PDFlib object", 0, "pdflib.cpp", opaque);
}
PDFCPP_TRY
{
PDF_set_parameter(p, "binding", "C++");
PDF_set_parameter(p, "objorient", "true");
}
PDFCPP_CATCH;
}
PDFlib::~PDFlib() throw()
{
m_PDFlib_api->PDF_delete(p);
m_PDFlib_api->PDF_shutdown();
}
void
PDFlib::activate_item(int id)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_activate_item(p, id);
PDFCPP_CATCH;
}
int
PDFlib::add_bookmark(string text, int parent, int p_open)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_add_bookmark2(p, CHAR(text), (int) LEN(text),
parent, p_open);
PDFCPP_CATCH;
return retval;
}
void
PDFlib::add_launchlink(double llx, double lly, double urx, double ury,
string filename) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_add_launchlink(p, llx, lly, urx, ury, CHAR(filename));
PDFCPP_CATCH;
}
void
PDFlib::add_locallink(double llx, double lly, double urx, double ury, int page,
string optlist) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_add_locallink(p, llx, lly, urx, ury, page, CHAR(optlist));
PDFCPP_CATCH;
}
void
PDFlib::add_nameddest(string name, string optlist) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_add_nameddest(p, CHAR(name), LEN(name), CHAR(optlist));
PDFCPP_CATCH;
}
void
PDFlib::add_note(double llx, double lly, double urx, double ury,
string contents, string title, string icon, int p_open)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_add_note2(p, llx, lly, urx, ury,
CHAR(contents), LEN(contents), CHAR(title), LEN(title), CHAR(icon),
p_open);
PDFCPP_CATCH;
}
void
PDFlib::add_pdflink(double llx, double lly, double urx, double ury,
string filename, int page, string optlist) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_add_pdflink(p, llx, lly, urx, ury, CHAR(filename),
page, CHAR(optlist));
PDFCPP_CATCH;
}
void
PDFlib::add_thumbnail(int image) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_add_thumbnail(p, image);
PDFCPP_CATCH;
}
void
PDFlib::add_weblink(double llx, double lly, double urx, double ury,
string url) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_add_weblink(p, llx, lly, urx, ury, CHAR(url));
PDFCPP_CATCH;
}
void
PDFlib::arc(double x, double y, double r, double alpha, double beta)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_arc(p, x, y, r, alpha, beta);
PDFCPP_CATCH;
}
void
PDFlib::arcn(double x, double y, double r, double alpha, double beta)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_arcn(p, x, y, r, alpha, beta);
PDFCPP_CATCH;
}
void
PDFlib::attach_file(double llx, double lly, double urx, double ury,
string filename, string description, string author,
string mimetype, string icon) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_attach_file2(p, llx, lly, urx, ury, CHAR(filename), 0,
CHAR(description), (int) LEN(description), CHAR(author),
(int) LEN(author), CHAR(mimetype), CHAR(icon));
PDFCPP_CATCH;
}
int
PDFlib::begin_document(string filename, string optlist)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_begin_document(p, CHAR(filename),
0, CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::begin_font(string fontname, double a, double b,
double c, double d, double e, double f, string optlist)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_begin_font(p, CHAR(fontname), 0,
a, b, c, d, e, f, CHAR(optlist));
PDFCPP_CATCH;
}
void
PDFlib::begin_glyph(string glyphname, double wx, double llx, double lly,
double urx, double ury) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_begin_glyph(p, CHAR(glyphname), wx, llx,
lly, urx, ury);
PDFCPP_CATCH;
}
int
PDFlib::begin_item(string tag, string optlist)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_begin_item(p, CHAR(tag), CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::begin_layer(int layer)
throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_begin_layer(p, layer);
PDFCPP_CATCH;
}
void
PDFlib::begin_page(double width, double height) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_begin_page(p, width, height);
PDFCPP_CATCH;
}
void
PDFlib::begin_page_ext(double width, double height, string optlist)
throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_begin_page_ext(p, width, height, CHAR(optlist));
PDFCPP_CATCH;
}
int
PDFlib::begin_pattern(double width, double height, double xstep, double ystep,
int painttype) throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_begin_pattern(p, width, height,
xstep, ystep, painttype);
PDFCPP_CATCH;
return retval;
}
int
PDFlib::begin_template(double width, double height)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY retval = m_PDFlib_api->PDF_begin_template(p, width, height);
PDFCPP_CATCH;
return retval;
}
void
PDFlib::circle(double x, double y, double r) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_circle(p, x, y, r);
PDFCPP_CATCH;
}
void
PDFlib::clip() throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_clip(p);
PDFCPP_CATCH;
}
void
PDFlib::close() throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_close(p);
PDFCPP_CATCH;
}
void
PDFlib::close_image(int image) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_close_image(p, image);
PDFCPP_CATCH;
}
void
PDFlib::close_pdi(int doc) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_close_pdi(p, doc);
PDFCPP_CATCH;
}
void
PDFlib::close_pdi_page(int page) throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_close_pdi_page(p, page);
PDFCPP_CATCH;
}
void
PDFlib::closepath() throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_closepath(p);
PDFCPP_CATCH;
}
void
PDFlib::closepath_fill_stroke() throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_closepath_fill_stroke(p);
PDFCPP_CATCH;
}
void
PDFlib::closepath_stroke() throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_closepath_stroke(p);
PDFCPP_CATCH;
}
void
PDFlib::concat(double a, double b, double c, double d, double e, double f)
throw(PDFlib::Exception)
{
PDFCPP_TRY m_PDFlib_api->PDF_concat(p, a, b, c, d, e, f);
PDFCPP_CATCH;
}
void
PDFlib::continue_text(string text) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_continue_text2(p, CHAR(text), (int) LEN(text));
PDFCPP_CATCH;
}
int
PDFlib::create_action(string type, string optlist)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_create_action(p, CHAR(type), CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::create_annotation(double llx, double lly, double urx, double ury,
string type, string optlist)
throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_create_annotation(p, llx, lly, urx, ury,
CHAR(type), CHAR(optlist));
PDFCPP_CATCH;
}
int
PDFlib::create_bookmark(string text, string optlist)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_create_bookmark(p, CHAR(text), LEN(text),
CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::create_field(double llx, double lly, double urx, double ury,
string name, string type, string optlist)
throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_create_field(p, llx, lly, urx,
ury, CHAR(name), LEN(name), CHAR(type), CHAR(optlist));
PDFCPP_CATCH;
}
void
PDFlib::create_fieldgroup(string name, string optlist)
throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_create_fieldgroup(p, CHAR(name), LEN(name),
CHAR(optlist));
PDFCPP_CATCH;
}
int
PDFlib::create_gstate (string optlist) throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_create_gstate(p, CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::create_pvf(string filename, const void *data, size_t size,
string optlist) throw(PDFlib::Exception)
{
PDFCPP_TRY
m_PDFlib_api->PDF_create_pvf(p, CHAR(filename), 0, data, size,
CHAR(optlist));
PDFCPP_CATCH;
}
int PDFlib::create_textflow(string text, string optlist)
throw(PDFlib::Exception)
{
int retval = 0;
PDFCPP_TRY
retval = m_PDFlib_api->PDF_create_textflow(p, CHAR(text), LEN(text),
CHAR(optlist));
PDFCPP_CATCH;
return retval;
}
void
PDFlib::curveto(double x1, double y1, double x2, double y2, double x3,
double y3)
throw(PDFlib::Exception)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -