From e1a1eb41f27272c4505060fb76df47fe0ee45a47 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Jul 2014 23:01:27 +0530 Subject: [PATCH] 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) --- src/calibre/utils/podofo/doc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp index a3df1ce53e..edecf44ba8 100644 --- a/src/calibre/utils/podofo/doc.cpp +++ b/src/calibre/utils/podofo/doc.cpp @@ -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) {