Restore the --uncompressed-pdf option

This commit is contained in:
Kovid Goyal 2019-07-23 15:49:53 +05:30
parent 0d1b99a4a4
commit 470193f222
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 22 additions and 0 deletions

View File

@ -126,6 +126,10 @@ class PDFOutput(OutputFormatPlugin):
help=_('Adjust page numbers, as needed. Syntax is a JavaScript expression for the page number.'
' For example, "if (n < 3) 0; else n - 3;", where n is current page number.')
),
OptionRecommendation(name='uncompressed_pdf',
recommended_value=False, help=_(
'Generate an uncompressed PDF, useful for debugging.')
),
}
def specialize_options(self, log, opts, input_fmt):

View File

@ -852,6 +852,9 @@ def convert(opf_path, opts, metadata=None, output_path=None, log=default_log, co
update_metadata(pdf_doc, PDFMetadata(metadata))
report_progress(1, _('Updated metadata in PDF'))
if opts.uncompressed_pdf:
pdf_doc.uncompress()
pdf_data = pdf_doc.write()
if output_path is None:
return pdf_data

View File

@ -128,6 +128,18 @@ PDFDoc_save_to_fileobj(PDFDoc *self, PyObject *args) {
return write_doc(self->doc, f);
}
static PyObject *
PDFDoc_uncompress_pdf(PDFDoc *self, PyObject *args) {
for (TIVecObjects it = self->doc->GetObjects().begin(); it != self->doc->GetObjects().end(); it++) {
if((*it)->HasStream()) {
PdfMemStream* stream = dynamic_cast<PdfMemStream*>((*it)->GetStream());
stream->Uncompress();
}
}
Py_RETURN_NONE;
}
// }}}
// extract_first_page() {{{
@ -714,6 +726,9 @@ static PyMethodDef PDFDoc_methods[] = {
{"save_to_fileobj", (PyCFunction)PDFDoc_save_to_fileobj, METH_VARARGS,
"Write the PDF document to the soecified file-like object."
},
{"uncompress", (PyCFunction)PDFDoc_uncompress_pdf, METH_NOARGS,
"Uncompress the PDF"
},
{"extract_first_page", (PyCFunction)PDFDoc_extract_first_page, METH_VARARGS,
"extract_first_page() -> Remove all but the first page."
},