diff --git a/src/calibre/ebooks/metadata/pdf.py b/src/calibre/ebooks/metadata/pdf.py index 147e3d2504..1af0662fbd 100644 --- a/src/calibre/ebooks/metadata/pdf.py +++ b/src/calibre/ebooks/metadata/pdf.py @@ -39,7 +39,7 @@ def get_metadata(stream, cover=True): if cover and 'cover' in info: data = info['cover'] if data is None: - prints(title, 'is an encrypted document, cover extraction not allowed.') + prints(title, 'has no pages, cover extraction impossible.') else: mi.cover_data = ('png', data) diff --git a/src/calibre/ebooks/pdf/main.cpp b/src/calibre/ebooks/pdf/main.cpp index e55edcae91..c0033190fa 100644 --- a/src/calibre/ebooks/pdf/main.cpp +++ b/src/calibre/ebooks/pdf/main.cpp @@ -52,7 +52,7 @@ extern "C" { reflow = new Reflow(pdfdata, size); info = reflow->get_info(); if (PyObject_IsTrue(cover)) { - if (!reflow->is_locked() && reflow->numpages() > 0) { + if (reflow->numpages() > 0) { vector *data = reflow->render_first_page(); if (data && data->size() > 0) { PyObject *d = PyBytes_FromStringAndSize(&((*data)[0]), data->size()); diff --git a/src/calibre/ebooks/pdf/reflow.cpp b/src/calibre/ebooks/pdf/reflow.cpp index cbd55f1fd2..43efe2c103 100644 --- a/src/calibre/ebooks/pdf/reflow.cpp +++ b/src/calibre/ebooks/pdf/reflow.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -684,6 +685,7 @@ void XMLOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, Reflow::Reflow(char *pdfdata, size_t sz) : pdfdata(pdfdata), current_font_size(-1), doc(NULL), obj() { + int err; this->obj.initNull(); if (globalParams == NULL) { globalParams = new GlobalParams(); @@ -694,9 +696,14 @@ Reflow::Reflow(char *pdfdata, size_t sz) : this->doc = new PDFDoc(str, NULL, NULL); if (!this->doc->isOk()) { + err = this->doc->getErrorCode(); ostringstream stm; - stm << "Failed to open PDF file"; - stm << " with error code: " << doc->getErrorCode(); + if (err == errEncrypted) + stm << "PDF is password protected."; + else { + stm << "Failed to open PDF file"; + stm << " with error code: " << err; + } delete this->doc; this->doc = NULL; throw ReflowException(stm.str().c_str()); @@ -706,9 +713,6 @@ Reflow::Reflow(char *pdfdata, size_t sz) : void Reflow::render() { - if (this->doc->isEncrypted()) { - throw ReflowException("Document is encrypted."); - } if (!this->doc->okToCopy()) cout << "Warning, this document has the copy protection flag set, ignoring." << endl; @@ -851,7 +855,6 @@ string Reflow::decode_info_string(Dict *info, const char *key) const { vector* Reflow::render_first_page(bool use_crop_box, double x_res, double y_res) { - if (this->is_locked()) throw ReflowException("Document is locked."); if (this->numpages() < 1) throw ReflowException("Document has no pages."); globalParams->setTextEncoding(encoding); globalParams->setEnableFreeType(yes);