pdfreflow now returns the number of pages in the document

This commit is contained in:
Kovid Goyal 2011-03-30 15:52:44 -06:00
parent 7095e33100
commit b449522862
3 changed files with 8 additions and 6 deletions

View File

@ -24,14 +24,14 @@ extern "C" {
pdfreflow_reflow(PyObject *self, PyObject *args) {
char *pdfdata;
Py_ssize_t size;
int first_page, last_page;
int first_page, last_page, num = 0;
if (!PyArg_ParseTuple(args, "s#ii", &pdfdata, &size, &first_page, &last_page))
return NULL;
try {
Reflow reflow(pdfdata, static_cast<std::ifstream::pos_type>(size));
reflow.render(first_page, last_page);
num = reflow.render(first_page, last_page);
} catch (std::exception &e) {
PyErr_SetString(PyExc_RuntimeError, e.what()); return NULL;
} catch (...) {
@ -39,7 +39,7 @@ extern "C" {
"Unknown exception raised while rendering PDF"); return NULL;
}
Py_RETURN_NONE;
return Py_BuildValue("i", num);
}
static PyObject *
@ -168,7 +168,7 @@ extern "C" {
PyMethodDef pdfreflow_methods[] = {
{"reflow", pdfreflow_reflow, METH_VARARGS,
"reflow(pdf_data, first_page, last_page)\n\n"
"Reflow the specified PDF."
"Reflow the specified PDF. Returns the number of pages in the PDF. If last_page is -1 renders to end of document."
},
{"get_metadata", pdfreflow_get_metadata, METH_VARARGS,
"get_metadata(pdf_data, cover)\n\n"

View File

@ -712,7 +712,7 @@ Reflow::Reflow(char *pdfdata, size_t sz) :
}
void
int
Reflow::render(int first_page, int last_page) {
if (!this->doc->okToCopy())
@ -739,6 +739,8 @@ Reflow::render(int first_page, int last_page) {
this->dump_outline();
delete xml_out;
return doc_pages;
}
void Reflow::dump_outline() {

View File

@ -66,7 +66,7 @@ class Reflow {
~Reflow();
/* Convert the PDF to XML. All files are output to the current directory */
void render(int first_page, int last_page);
int render(int first_page, int last_page);
/* Get the PDF Info Dictionary */
map<string, string> get_info();