mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF metadata: Don't refuse to get cover from PDF files that have their encryption bit set but are not actually encrypted
This commit is contained in:
parent
2c8de06afb
commit
c5869035e8
@ -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)
|
||||
|
||||
|
@ -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<char> *data = reflow->render_first_page();
|
||||
if (data && data->size() > 0) {
|
||||
PyObject *d = PyBytes_FromStringAndSize(&((*data)[0]), data->size());
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <Outline.h>
|
||||
#include <PDFDocEncoding.h>
|
||||
#include <poppler/ErrorCodes.h>
|
||||
#include <goo/GooList.h>
|
||||
#include <SplashOutputDev.h>
|
||||
#include <splash/SplashBitmap.h>
|
||||
@ -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;
|
||||
if (err == errEncrypted)
|
||||
stm << "PDF is password protected.";
|
||||
else {
|
||||
stm << "Failed to open PDF file";
|
||||
stm << " with error code: " << doc->getErrorCode();
|
||||
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<char>* 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user