mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add func to get num of pages ina pdf using poppler
This commit is contained in:
parent
bb9d414c4a
commit
dd542318af
@ -85,6 +85,32 @@ extern "C" {
|
|||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
pdfreflow_get_numpages(PyObject *self, PyObject *args) {
|
||||||
|
char *pdfdata;
|
||||||
|
int num = 0;
|
||||||
|
Py_ssize_t size;
|
||||||
|
map<string,string> info;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "s#", &pdfdata, &size))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
Reflow *reflow = NULL;
|
||||||
|
try {
|
||||||
|
reflow = new Reflow(pdfdata, size);
|
||||||
|
num = reflow->numpages();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, e.what()); delete reflow; return NULL;
|
||||||
|
} catch (...) {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError,
|
||||||
|
"Unknown exception raised while getting metadata from PDF"); delete reflow; return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete reflow; reflow = NULL;
|
||||||
|
return Py_BuildValue("i", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pdfreflow_set_metadata(PyObject *self, PyObject *args) {
|
pdfreflow_set_metadata(PyObject *self, PyObject *args) {
|
||||||
char *pdfdata;
|
char *pdfdata;
|
||||||
@ -144,6 +170,10 @@ extern "C" {
|
|||||||
"get_metadata(info_dict)\n\n"
|
"get_metadata(info_dict)\n\n"
|
||||||
"Set metadata in the specified PDF. Currently broken."
|
"Set metadata in the specified PDF. Currently broken."
|
||||||
},
|
},
|
||||||
|
{"get_numpages", pdfreflow_get_numpages, METH_VARARGS,
|
||||||
|
"get_numpages(pdf_data)\n\n"
|
||||||
|
"Get number of pages in the PDF."
|
||||||
|
},
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user