pdf.c
来自「windows下PDF文档的开发包」· C语言 代码 · 共 2,468 行 · 第 1/5 页
C
2,468 行
convert_to_double_ex(ury);
convert_to_long_ex(page);
convert_to_string_ex(optlist);
PDF_add_locallink(pdf,
(float) Z_DVAL_PP(llx),
(float) Z_DVAL_PP(lly),
(float) Z_DVAL_PP(urx),
(float) Z_DVAL_PP(ury),
Z_LVAL_PP(page),
Z_STRVAL_PP(optlist));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_add_note(int pdfdoc, float llx, float lly, float urx, float ury, string contents, string title, string icon, int open)
* Add a note annotation. icon is one of of "comment", "insert", "note", "paragraph", "newparagraph", "key", or "help". */
PHP_FUNCTION(pdf_add_note)
{
zval **p, **llx, **lly, **urx, **ury, **contents, **title, **icon, **open;
PDF *pdf;
if (ZEND_NUM_ARGS() != 9 || zend_get_parameters_ex(9, &p, &llx, &lly, &urx, &ury, &contents, &title, &icon, &open) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
convert_to_double_ex(llx);
convert_to_double_ex(lly);
convert_to_double_ex(urx);
convert_to_double_ex(ury);
convert_to_string_ex(contents);
convert_to_string_ex(title);
convert_to_string_ex(icon);
convert_to_long_ex(open);
PDF_add_note2(pdf,
(float) Z_DVAL_PP(llx),
(float) Z_DVAL_PP(lly),
(float) Z_DVAL_PP(urx),
(float) Z_DVAL_PP(ury),
Z_STRVAL_PP(contents),
Z_STRLEN_PP(contents),
Z_STRVAL_PP(title),
Z_STRLEN_PP(title),
Z_STRVAL_PP(icon),
Z_LVAL_PP(open));
RETURN_TRUE;
}
/* }}} */
/* TODO [optlist] */
/* {{{ proto void pdf_add_pdflink(int pdfdoc, float llx, float lly, float urx, float ury, string filename, int page, string optlist)
* Add a file link annotation (to a PDF target). */
PHP_FUNCTION(pdf_add_pdflink)
{
zval **p, **llx, **lly, **urx, **ury, **filename, **page, **optlist;
PDF *pdf;
const char * vfilename;
if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &p, &llx, &lly, &urx, &ury, &filename, &page, &optlist) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
convert_to_double_ex(llx);
convert_to_double_ex(lly);
convert_to_double_ex(urx);
convert_to_double_ex(ury);
convert_to_string_ex(filename);
convert_to_long_ex(page);
convert_to_string_ex(optlist);
#ifdef VIRTUAL_DIR
# if ZEND_MODULE_API_NO >= 20010901
virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
# else
virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
# endif
#else
vfilename = Z_STRVAL_PP(filename);
#endif
PDF_add_pdflink(pdf, (float) Z_DVAL_PP(llx),
(float) Z_DVAL_PP(lly),
(float) Z_DVAL_PP(urx),
(float) Z_DVAL_PP(ury),
vfilename,
Z_LVAL_PP(page),
Z_STRVAL_PP(optlist));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_add_weblink(int pdfdoc, float llx, float lly, float urx, float ury, string url)
* Add a weblink annotation to a target URL on the Web. */
PHP_FUNCTION(pdf_add_weblink)
{
zval **arg1, **arg2, **arg3, **arg4, **arg5, **arg6;
PDF *pdf;
if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
convert_to_double_ex(arg2);
convert_to_double_ex(arg3);
convert_to_double_ex(arg4);
convert_to_double_ex(arg5);
convert_to_string_ex(arg6);
PDF_add_weblink(pdf, (float) Z_DVAL_PP(arg2),
(float) Z_DVAL_PP(arg3),
(float) Z_DVAL_PP(arg4),
(float) Z_DVAL_PP(arg5),
Z_STRVAL_PP(arg6));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_attach_file(int pdfdoc, float lly, float lly, float urx, float ury, string filename, string description, string author, string mimetype, string icon)
* Add a file attachment annotation. icon is one of "graph", "paperclip", "pushpin", or "tag". */
PHP_FUNCTION(pdf_attach_file)
{
zval **p, **llx, **lly, **urx, **ury, **filename, **description, **author, **mimetype, **icon;
PDF *pdf;
const char * vfilename;
if (ZEND_NUM_ARGS() != 10 || zend_get_parameters_ex(10, &p, &llx, &lly, &urx, &ury, &filename, &description, &author, &mimetype, &icon) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
convert_to_double_ex(llx);
convert_to_double_ex(lly);
convert_to_double_ex(urx);
convert_to_double_ex(ury);
convert_to_string_ex(filename);
convert_to_string_ex(description);
convert_to_string_ex(author);
convert_to_string_ex(mimetype);
convert_to_string_ex(icon);
#ifdef VIRTUAL_DIR
# if ZEND_MODULE_API_NO >= 20010901
virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
# else
virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
# endif
#else
vfilename = Z_STRVAL_PP(filename);
#endif
PDF_attach_file2(pdf,
(float) Z_DVAL_PP(llx),
(float) Z_DVAL_PP(lly),
(float) Z_DVAL_PP(urx),
(float) Z_DVAL_PP(ury),
vfilename,
0,
Z_STRVAL_PP(description),
Z_STRLEN_PP(description),
Z_STRVAL_PP(author),
Z_STRLEN_PP(author),
Z_STRVAL_PP(mimetype),
Z_STRVAL_PP(icon));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_set_border_color(int pdfdoc, float red, float green, float blue)
* Set the border color for all kinds of annotations. */
PHP_FUNCTION(pdf_set_border_color)
{
zval **arg1, **arg2, **arg3, **arg4;
PDF *pdf;
if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
convert_to_double_ex(arg2);
convert_to_double_ex(arg3);
convert_to_double_ex(arg4);
PDF_set_border_color(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3), (float) Z_DVAL_PP(arg4));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_set_border_dash(int pdfdoc, float b, float w)
* Set the border dash style for all kinds of annotations. See PDF_setdash(). */
PHP_FUNCTION(pdf_set_border_dash)
{
zval **arg1, **arg2, **arg3;
PDF *pdf;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
convert_to_double_ex(arg2);
convert_to_double_ex(arg3);
PDF_set_border_dash(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_set_border_style(int pdfdoc, string style, float width)
* Set the border style for all kinds of annotations. style is "solid" or "dashed". */
PHP_FUNCTION(pdf_set_border_style)
{
zval **arg1, **arg2, **arg3;
PDF *pdf;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
convert_to_string_ex(arg2);
convert_to_double_ex(arg3);
PDF_set_border_style(pdf, Z_STRVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
RETURN_TRUE;
}
/* }}} */
/* p_basic.c */
/* {{{ proto void pdf_begin_page(int pdfdoc, float width, float height)
* Add a new page to the document. */
PHP_FUNCTION(pdf_begin_page)
{
zval **arg1, **arg2, **arg3;
PDF *pdf;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
convert_to_double_ex(arg2);
convert_to_double_ex(arg3);
PDF_begin_page(pdf, (float) Z_DVAL_PP(arg2), (float) Z_DVAL_PP(arg3));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_close(int pdfdoc)
* Close the generated PDF file, and release all document-related resources. */
PHP_FUNCTION(pdf_close)
{
zval **arg1;
PDF *pdf;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
PDF_close(pdf);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool pdf_delete(int pdfdoc)
* Delete the PDF object, and free all internal resources. */
PHP_FUNCTION(pdf_delete)
{
zval **arg1;
PDF *pdf;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
#ifndef Z_RESVAL /* for php 4.0.3pl1 */
#define Z_RESVAL(zval) (zval).value.lval
#define Z_RESVAL_PP(zval_pp) Z_RESVAL(**zval_pp)
#endif
zend_list_delete(Z_RESVAL_PP(arg1));
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void pdf_end_page(int pdfdoc)
* Finish the page. */
PHP_FUNCTION(pdf_end_page)
{
zval **arg1;
PDF *pdf;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
PDF_end_page(pdf);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int pdf_get_apiname(int pdfdoc);
* Get the name of the API function which threw the last exception or failed. */
PHP_FUNCTION(pdf_get_apiname)
{
zval **p;
PDF *pdf;
char *buffer;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
buffer = PDF_get_apiname(pdf);
RETURN_STRING(buffer, 1);
}
/* }}} */
/* {{{ proto int pdf_get_buffer(int pdfdoc)
* Get the contents of the PDF output buffer. The result must be used by the client before calling any other PDFlib function. */
PHP_FUNCTION(pdf_get_buffer)
{
zval **arg1;
long size;
PDF *pdf;
const char *buffer;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object", le_pdf);
buffer = PDF_get_buffer(pdf, &size);
RETURN_STRINGL((char *)buffer, size, 1);
}
/* }}} */
/* {{{ proto int pdf_get_errmsg(int pdfdoc);
* Get the contents of the PDF output buffer. The result must be used by
* the client before calling any other PDFlib function. */
PHP_FUNCTION(pdf_get_errmsg)
{
zval **p;
PDF *pdf;
char *buffer;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
buffer = PDF_get_errmsg(pdf);
RETURN_STRING(buffer, 1);
}
/* }}} */
/* {{{ proto int pdf_get_errnum(int pdfdoc);
* Get the descriptive text of the last thrown exception, or the reason of
* a failed function call.*/
PHP_FUNCTION(pdf_get_errnum)
{
zval **p;
PDF *pdf;
int retval;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &p) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
retval = PDF_get_errnum(pdf);
RETURN_LONG(retval);
}
/* }}} */
/* {{{ proto int pdf_new()
* Creates a new PDF object */
PHP_FUNCTION(pdf_new)
{
PDF *pdf;
pdf = PDF_new2(custom_errorhandler, pdf_emalloc, pdf_realloc, pdf_efree, NULL);
if (pdf != NULL) {
PDF_set_parameter(pdf, "imagewarning", "true");
/* Trigger special handling of PDFlib-handles for PHP */
PDF_set_parameter(pdf, "hastobepos", "true");
PDF_set_parameter(pdf, "binding", "PHP");
ZEND_REGISTER_RESOURCE(return_value, pdf, le_pdf);
} else {
php_error(E_ERROR, "PDF_new: internal error");
}
}
/* }}} */
/* {{{ proto int pdf_open_file(int pdfdoc [, char filename])
* Create a new PDF file using the supplied file name. */
PHP_FUNCTION(pdf_open_file)
{
zval **p, **filename;
int pdf_file;
const char *vfilename;
int argc;
PDF *pdf;
if((argc = ZEND_NUM_ARGS()) > 2)
WRONG_PARAM_COUNT;
if (argc == 1) {
if (zend_get_parameters_ex(1, &p) == FAILURE)
WRONG_PARAM_COUNT;
} else {
if (zend_get_parameters_ex(2, &p, &filename) == FAILURE)
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
if (argc == 2) {
convert_to_string_ex(filename);
#ifdef VIRTUAL_DIR
# if ZEND_MODULE_API_NO >= 20010901
virtual_filepath(Z_STRVAL_PP(filename), &vfilename TSRMLS_CC);
# else
virtual_filepath(Z_STRVAL_PP(filename), &vfilename);
# endif
#else
vfilename = Z_STRVAL_PP(filename);
#endif
pdf_file = PDF_open_file(pdf, vfilename);
} else {
/* open in memory */
pdf_file = PDF_open_file(pdf, "");
}
RETURN_LONG(pdf_file); /* change return from -1 to 0 handled by PDFlib */
}
/* }}} */
/* p_block.c */
/* TODO [optlist] */
/* {{{ proto int pdf_fill_imageblock(int pdfdoc, int page, string spotname, int image, string optlist);
* Process an image block according to its properties. */
PHP_FUNCTION(pdf_fill_imageblock)
{
zval **p, **page, **blockname, **image, **optlist;
PDF *pdf;
int retval;
if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &p, &page, &blockname, &image, &optlist) == FAILURE) {
WRONG_PARAM_COUNT;
}
ZEND_FETCH_RESOURCE(pdf, PDF *, p, -1, "pdf object", le_pdf);
convert_to_long_ex(page);
convert_to_string_ex(blockname);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?