Skip to content

Commit

Permalink
Add a poppler_version function
Browse files Browse the repository at this point in the history
  • Loading branch information
jalan committed Dec 6, 2024
1 parent 73aab2a commit f1cd011
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pdftotext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <poppler/cpp/poppler-document.h>
#include <poppler/cpp/poppler-global.h>
#include <poppler/cpp/poppler-page.h>
#include <poppler/cpp/poppler-version.h>

#include <algorithm>
#include <climits>
Expand Down Expand Up @@ -244,10 +245,22 @@ static PyTypeObject PDFType = {

static void do_nothing(const std::string&, void*) {}

static PyObject* poppler_version(PyObject* self, PyObject* args) {
return PyUnicode_FromString(poppler::version_string().c_str());
}

static PyMethodDef Methods[] = {
{
"poppler_version",
poppler_version,
METH_NOARGS,
"Get the version of the poppler library in use.",
},
{NULL, NULL, 0, NULL}, // sentinel
};

static PyModuleDef pdftotextmodule = {
PyModuleDef_HEAD_INIT,
"pdftotext",
"Simple PDF text extraction.",
PyModuleDef_HEAD_INIT, "pdftotext", "Simple PDF text extraction.", -1, Methods,
};

PyMODINIT_FUNC PyInit_pdftotext() {
Expand Down
13 changes: 13 additions & 0 deletions tests/test_pdftotext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io
import pkg_resources
import subprocess
import unittest

import pdftotext
Expand Down Expand Up @@ -271,3 +272,15 @@ def test_raw_vs_physical(self):
pdf_raw = pdftotext.PDF(get_file(filename), raw=True)
pdf_physical = pdftotext.PDF(get_file(filename), physical=True)
self.assertNotEqual(pdf_raw[0], pdf_physical[0])


class VersionTest(unittest.TestCase):
"""Test the poppler_version function."""

def test_poppler_version(self):
poppler_version = (
subprocess.check_output(["pkg-config", "--modversion", "poppler-cpp"])
.decode()
.strip()
)
self.assertEqual(pdftotext.poppler_version(), poppler_version)

0 comments on commit f1cd011

Please sign in to comment.