Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower minimum poppler-cpp version to 0.26.0 #13

Merged
merged 8 commits into from
Sep 9, 2020
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_subdirectory(pybind11)


find_package(PkgConfig REQUIRED)
pkg_check_modules(POPPLER REQUIRED IMPORTED_TARGET poppler-cpp>=0.62.0)
pkg_check_modules(POPPLER REQUIRED IMPORTED_TARGET poppler-cpp>=0.26.0)

add_library(global_ MODULE src/cpp/global.cpp)
target_link_libraries(global_ PRIVATE pybind11::module PkgConfig::POPPLER )
Expand Down
6 changes: 6 additions & 0 deletions src/cpp/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,20 @@ PYBIND11_MODULE(document, m)
.def("create_toc", &document::create_toc)
.def("embedded_files", &document::embedded_files)
.def("fonts", &document::fonts)
#if HAS_VERSION(0, 46)
.def("get_author", &document::get_author)
.def("get_creation_date", &document::get_creation_date)
.def("get_creator", &document::get_creator)
.def("get_keywords", &document::get_keywords)
.def("get_modification_date", &document::get_modification_date)
#endif
.def("get_pdf_id", &binding::pdf_id)
.def("get_pdf_version", &binding::pdf_version)
#if HAS_VERSION(0, 46)
.def("get_producer", &document::get_producer)
.def("get_subject", &document::get_subject)
.def("get_title", &document::get_title)
#endif
.def("has_embedded_files", &document::has_embedded_files)
.def("has_permission", &document::has_permission, py::arg("which"))
.def("info_date", &document::info_date, py::arg("key"))
Expand All @@ -129,6 +133,7 @@ PYBIND11_MODULE(document, m)
.def("page_layout", &document::page_layout)
.def("page_mode", &document::page_mode)
.def("pages", &document::pages)
#if HAS_VERSION(0, 46)
.def("remove_info", &document::remove_info)
.def("save", &document::save, py::arg("file_name"))
.def("save_a_copy", &document::save_a_copy, py::arg("file_name"))
Expand All @@ -142,6 +147,7 @@ PYBIND11_MODULE(document, m)
.def("set_producer", &document::set_producer, py::arg("producer"))
.def("set_subject", &document::set_subject, py::arg("subject"))
.def("set_title", &document::set_title, py::arg("title"))
#endif
.def("unlock", &document::unlock, py::arg("owner_password"), py::arg("user_password"));

m.def("load_from_data", &binding::load_from_data, py::arg("file_data"), py::arg("owner_password") = "", py::arg("user_password") = "");
Expand Down
48 changes: 43 additions & 5 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,33 @@ def locked_document(data_path):
return document.load_from_file(data_path / "document.pdf")


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_load_from_data(data_path):
file_data = (data_path / "document.pdf").read_bytes()
pdf_document = document.load_from_data(file_data, "owner", "user")
assert pdf_document.author == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_load_with_path(data_path):
pdf_document = document.load(data_path / "document.pdf", "owner", "user")
assert pdf_document.author == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_load_with_filename(data_path):
pdf_document = document.load(str(data_path / "document.pdf"), "owner", "user")
assert pdf_document.author == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_load_with_bytes(data_path):
data = (data_path / "document.pdf").read_bytes()
pdf_document = document.load(data, "owner", "user")
assert pdf_document.author == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_load_with_file(data_path):
with (data_path / "document.pdf").open("rb") as f:
pdf_document = document.load(f, "owner", "user")
Expand All @@ -69,6 +74,7 @@ def test_load_with_invalid_type():
document.load(42)


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_save(pdf_document, tmp_path):
copy_document = tmp_path / "copy.pdf"
pdf_document.author = "Valérie Tremblay"
Expand All @@ -78,6 +84,7 @@ def test_save(pdf_document, tmp_path):
assert pdf_copy.author == "Valérie Tremblay"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_save_a_copy(pdf_document, tmp_path):
copy_document = tmp_path / "copy.pdf"
pdf_document.author = "Valérie Tremblay"
Expand All @@ -95,24 +102,29 @@ def test_embedded_file(pdf_document):
assert pdf_document.embedded_files() == []


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_author(pdf_document):
assert pdf_document.author == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_creation_date(pdf_document):
assert pdf_document.creation_date.astimezone(timezone.utc) == datetime(
2020, 3, 26, 1, 19, 50, tzinfo=timezone.utc
)


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_creator(pdf_document):
assert pdf_document.creator == "Writer"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_keywords(pdf_document):
assert pdf_document.keywords == ""


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_modification_date(pdf_document):
assert pdf_document.modification_date is None

Expand All @@ -128,14 +140,17 @@ def test_get_pdf_version(pdf_document):
assert version == (1, 5)


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_producer(pdf_document):
assert pdf_document.producer == "LibreOffice 6.4"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_subject(pdf_document):
assert pdf_document.subject == ""


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_get_title(pdf_document):
assert pdf_document.title == ""

Expand All @@ -158,14 +173,22 @@ def test_has_permission(pdf_document):

def test_info_date(pdf_document):
date = pdf_document.info_date("CreationDate")
assert date.astimezone(timezone.utc) == datetime(
2020, 3, 26, 1, 19, 50, tzinfo=timezone.utc
)
if version() < (0, 46, 0):
assert date.astimezone(timezone.utc) == datetime(
2020, 3, 25, 21, 19, 50, tzinfo=timezone.utc
)
Comment on lines +194 to +197
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange... Do you think this is related to:

cpp:
* switched from detail::convert_date() to core's dateStringToTime()

in version 0.45?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are-you sure the wrong date is related with the poppler version? On my side, the date is the same with older poppler version.... Are you sure you computer has the right timezone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a closer look, I'm using inside an AWS SageMaker notebook, so it might not be set. However, maybe there is somewhere else the timezone is being used incorrectly.

else:
assert date.astimezone(timezone.utc) == datetime(
2020, 3, 26, 1, 19, 50, tzinfo=timezone.utc
)


def test_info_key(pdf_document):
info = pdf_document.info_key("Author")
assert info == "Charles Brunet"
if version() < (0, 46, 0):
assert info == "Charles"
Comment on lines +206 to +207
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to you explain this? Do you think it is related to

    cpp:
     * pass len to GooString constructor in detail::ustring_to_unicode_GooString(). Bug #96426

in poppler 0.46?

else:
assert info == "Charles Brunet"


def test_info_keys(pdf_document):
Expand All @@ -190,65 +213,76 @@ def test_metadata(pdf_document):
assert meta == ""


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_author(pdf_document):
author = "Valérie Tremblay"
pdf_document.author = author
assert pdf_document.author == author


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_creation_date(pdf_document):
d = datetime(1980, 7, 19, 10, 30, 50)
pdf_document.creation_date = d
assert pdf_document.creation_date == d


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_empty_creation_date(pdf_document):
pdf_document.creation_date = None
assert "CreationDate" not in pdf_document.info_keys()


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_creator(pdf_document):
creator = "Me"
pdf_document.creator = creator
assert pdf_document.creator == creator


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_keywords(pdf_document):
keywords = "one, two, three"
pdf_document.keywords = keywords
assert pdf_document.keywords == keywords


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_modification_date(pdf_document):
d = datetime(1980, 7, 19, 10, 30, 50)
pdf_document.modification_date = d
assert pdf_document.modification_date == d


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_producer(pdf_document):
producer = "Me"
pdf_document.producer = producer
assert pdf_document.producer == producer


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_subject(pdf_document):
subject = "Me"
pdf_document.subject = subject
assert pdf_document.subject == subject


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_title(pdf_document):
title = "The document title"
pdf_document.title = title
assert pdf_document.title == title


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_info_date(pdf_document):
d = datetime(1980, 7, 19, 10, 30, 50)
assert pdf_document.set_info_date("CreationDate", d) is True
assert pdf_document.creation_date == d


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_set_info_key(pdf_document):
author = "Valérie Tremblay"
assert pdf_document.set_info_key("Author", author) is True
Expand All @@ -257,9 +291,13 @@ def test_set_info_key(pdf_document):

def test_infos(pdf_document):
infos = pdf_document.infos()
assert infos["Author"] == "Charles Brunet"
if version() < (0, 46, 0):
assert infos['Author'] == 'Charles'
else:
assert infos["Author"] == "Charles Brunet"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_remove_info(pdf_document):
pdf_document.remove_info()
assert not pdf_document.infos()
Expand Down