mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF metadata: When updating the XMP metadata in PDF files, compress the metadata written to the PDF. This is particularly useful when the PDF file has an existing XMP metadata block with very large amounts of data in it. Fixes #1341549 [Embed Metadata for PDF consistently adds 0.5MB to book size](https://bugs.launchpad.net/calibre/+bug/1341549)
This commit is contained in:
parent
245050d593
commit
e1a1eb41f2
@ -280,18 +280,20 @@ PDFDoc_set_xmp_metadata(PDFDoc *self, PyObject *args) {
|
||||
long len = 0;
|
||||
PoDoFo::PdfObject *metadata = NULL, *catalog = NULL;
|
||||
PoDoFo::PdfStream *str = NULL;
|
||||
TVecFilters compressed(1);
|
||||
compressed[0] = ePdfFilter_FlateDecode;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#", &raw, &len)) return NULL;
|
||||
try {
|
||||
if ((metadata = self->doc->GetMetadata()) != NULL) {
|
||||
if ((str = metadata->GetStream()) == NULL) { PyErr_NoMemory(); goto error; }
|
||||
str->Set(raw, len, PoDoFo::TVecFilters());
|
||||
str->Set(raw, len, compressed);
|
||||
} else {
|
||||
if ((catalog = self->doc->GetCatalog()) == NULL) { PyErr_SetString(PyExc_ValueError, "Cannot set XML metadata as this document has no catalog"); goto error; }
|
||||
if ((metadata = self->doc->GetObjects().CreateObject("Metadata")) == NULL) { PyErr_NoMemory(); goto error; }
|
||||
if ((str = metadata->GetStream()) == NULL) { PyErr_NoMemory(); goto error; }
|
||||
metadata->GetDictionary().AddKey(PoDoFo::PdfName("Subtype"), PoDoFo::PdfName("XML"));
|
||||
str->Set(raw, len, PoDoFo::TVecFilters());
|
||||
str->Set(raw, len, compressed);
|
||||
catalog->GetDictionary().AddKey(PoDoFo::PdfName("Metadata"), metadata->Reference());
|
||||
}
|
||||
} catch(const PdfError & err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user