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:
|
if cover and 'cover' in info:
|
||||||
data = info['cover']
|
data = info['cover']
|
||||||
if data is None:
|
if data is None:
|
||||||
prints(title, 'is an encrypted document, cover extraction not allowed.')
|
prints(title, 'has no pages, cover extraction impossible.')
|
||||||
else:
|
else:
|
||||||
mi.cover_data = ('png', data)
|
mi.cover_data = ('png', data)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ extern "C" {
|
|||||||
reflow = new Reflow(pdfdata, size);
|
reflow = new Reflow(pdfdata, size);
|
||||||
info = reflow->get_info();
|
info = reflow->get_info();
|
||||||
if (PyObject_IsTrue(cover)) {
|
if (PyObject_IsTrue(cover)) {
|
||||||
if (!reflow->is_locked() && reflow->numpages() > 0) {
|
if (reflow->numpages() > 0) {
|
||||||
vector<char> *data = reflow->render_first_page();
|
vector<char> *data = reflow->render_first_page();
|
||||||
if (data && data->size() > 0) {
|
if (data && data->size() > 0) {
|
||||||
PyObject *d = PyBytes_FromStringAndSize(&((*data)[0]), data->size());
|
PyObject *d = PyBytes_FromStringAndSize(&((*data)[0]), data->size());
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <Outline.h>
|
#include <Outline.h>
|
||||||
#include <PDFDocEncoding.h>
|
#include <PDFDocEncoding.h>
|
||||||
|
#include <poppler/ErrorCodes.h>
|
||||||
#include <goo/GooList.h>
|
#include <goo/GooList.h>
|
||||||
#include <SplashOutputDev.h>
|
#include <SplashOutputDev.h>
|
||||||
#include <splash/SplashBitmap.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) :
|
Reflow::Reflow(char *pdfdata, size_t sz) :
|
||||||
pdfdata(pdfdata), current_font_size(-1), doc(NULL), obj()
|
pdfdata(pdfdata), current_font_size(-1), doc(NULL), obj()
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
this->obj.initNull();
|
this->obj.initNull();
|
||||||
if (globalParams == NULL) {
|
if (globalParams == NULL) {
|
||||||
globalParams = new GlobalParams();
|
globalParams = new GlobalParams();
|
||||||
@ -694,9 +696,14 @@ Reflow::Reflow(char *pdfdata, size_t sz) :
|
|||||||
this->doc = new PDFDoc(str, NULL, NULL);
|
this->doc = new PDFDoc(str, NULL, NULL);
|
||||||
|
|
||||||
if (!this->doc->isOk()) {
|
if (!this->doc->isOk()) {
|
||||||
|
err = this->doc->getErrorCode();
|
||||||
ostringstream stm;
|
ostringstream stm;
|
||||||
stm << "Failed to open PDF file";
|
if (err == errEncrypted)
|
||||||
stm << " with error code: " << doc->getErrorCode();
|
stm << "PDF is password protected.";
|
||||||
|
else {
|
||||||
|
stm << "Failed to open PDF file";
|
||||||
|
stm << " with error code: " << err;
|
||||||
|
}
|
||||||
delete this->doc;
|
delete this->doc;
|
||||||
this->doc = NULL;
|
this->doc = NULL;
|
||||||
throw ReflowException(stm.str().c_str());
|
throw ReflowException(stm.str().c_str());
|
||||||
@ -706,9 +713,6 @@ Reflow::Reflow(char *pdfdata, size_t sz) :
|
|||||||
|
|
||||||
void
|
void
|
||||||
Reflow::render() {
|
Reflow::render() {
|
||||||
if (this->doc->isEncrypted()) {
|
|
||||||
throw ReflowException("Document is encrypted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->doc->okToCopy())
|
if (!this->doc->okToCopy())
|
||||||
cout << "Warning, this document has the copy protection flag set, ignoring." << endl;
|
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,
|
vector<char>* Reflow::render_first_page(bool use_crop_box, double x_res,
|
||||||
double y_res) {
|
double y_res) {
|
||||||
if (this->is_locked()) throw ReflowException("Document is locked.");
|
|
||||||
if (this->numpages() < 1) throw ReflowException("Document has no pages.");
|
if (this->numpages() < 1) throw ReflowException("Document has no pages.");
|
||||||
globalParams->setTextEncoding(encoding);
|
globalParams->setTextEncoding(encoding);
|
||||||
globalParams->setEnableFreeType(yes);
|
globalParams->setEnableFreeType(yes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user