Skip to content

Commit 73317d3

Browse files
authored
improve poppler encryption handling (#457)
1 parent f9c74d3 commit 73317d3

7 files changed

Lines changed: 18 additions & 19 deletions

File tree

scripts/conan

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/odr/html.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ struct HtmlConfig {
9898
bool format_html{false};
9999
std::uint8_t html_indent{2};
100100

101+
// background image
102+
std::string background_image_format{"png"};
103+
104+
// drm
105+
bool no_drm{false};
106+
101107
std::optional<std::string> output_path;
102108
HtmlResourceLocator resource_locator;
103109

src/odr/internal/html/pdf2htmlex_wrapper.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ pdf2htmlEX::Param create_params(PDFDoc &pdf_doc, const HtmlConfig &config,
8282
param.text_dpi = 300;
8383

8484
// background
85-
param.bg_format = "png";
85+
param.bg_format = config.background_image_format;
8686
param.svg_node_count_limit = -1;
8787
param.svg_embed_bitmap = 1;
8888

8989
// encryption
9090
param.owner_password = "";
9191
param.user_password = "";
92-
param.no_drm = 1;
92+
param.no_drm = config.no_drm ? 1 : 0;
9393

9494
// misc
9595
param.clean_tmp = 1;
@@ -312,10 +312,6 @@ odr::HtmlService html::create_poppler_pdf_service(
312312
html_renderer_param->delay_background = 1;
313313
}
314314

315-
if (!pdf_doc.okToCopy() && html_renderer_param->no_drm == 0) {
316-
throw DocumentCopyProtectedException();
317-
}
318-
319315
// TODO not sure what the `progPath` is used for. it cannot be `nullptr`
320316
// TODO potentially just a cache dir?
321317
auto html_renderer = std::make_shared<pdf2htmlEX::HTMLRenderer>(

src/odr/internal/pdf_poppler/poppler_pdf_file.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ void PopplerPdfFile::open(const std::optional<std::string> &password) {
5454

5555
m_file_meta.type = FileType::portable_document_format;
5656
m_file_meta.mimetype = "application/pdf";
57-
m_file_meta.password_encrypted = m_pdf_doc->isEncrypted();
57+
// for some reason `isEncrypted` can return `true` even if the file is opened
58+
// without password
59+
m_file_meta.password_encrypted =
60+
m_encryption_state == EncryptionState::encrypted ||
61+
(password_goo.has_value() && m_pdf_doc->isEncrypted());
5862
m_file_meta.document_meta.emplace();
5963
m_file_meta.document_meta->document_type = DocumentType::text;
6064
if (m_encryption_state != EncryptionState::encrypted) {
@@ -73,8 +77,7 @@ DecoderEngine PopplerPdfFile::decoder_engine() const noexcept {
7377
FileMeta PopplerPdfFile::file_meta() const noexcept { return m_file_meta; }
7478

7579
bool PopplerPdfFile::password_encrypted() const noexcept {
76-
return m_encryption_state == EncryptionState::encrypted ||
77-
m_encryption_state == EncryptionState::decrypted;
80+
return m_file_meta.password_encrypted;
7881
}
7982

8083
EncryptionState PopplerPdfFile::encryption_state() const noexcept {

test/data/input/odr-public

test/src/html_output_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <filesystem>
1111
#include <fstream>
12-
#include <iostream>
1312
#include <optional>
1413
#include <string>
1514

@@ -54,7 +53,6 @@ TEST_P(HtmlOutputTests, html_meta) {
5453
const TestParams &params = GetParam();
5554
const TestFile &test_file = params.test_file;
5655
const DecoderEngine engine = params.engine;
57-
const std::string &test_repo = params.test_repo;
5856
const std::string &output_path = params.output_path;
5957
const std::string &output_path_prefix = params.output_path_prefix;
6058

@@ -76,7 +74,8 @@ TEST_P(HtmlOutputTests, html_meta) {
7674
// TODO fix pdf implementation
7775
if (engine == DecoderEngine::odr &&
7876
test_file.type == FileType::portable_document_format &&
79-
test_repo != "odr-public") {
77+
(test_file.short_path.starts_with("odr-private") ||
78+
test_file.short_path == "odr-public/pdf/Casio_WVA-M650-7AJF.pdf")) {
8079
GTEST_SKIP();
8180
}
8281

0 commit comments

Comments
 (0)