mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF metadata: Fix a regression that broke updating metadata in PDF files without an /Info dictionary
This commit is contained in:
parent
1f296569f3
commit
82846b43c7
@ -259,5 +259,13 @@ def test_podofo():
|
|||||||
raise ValueError('Appending failed')
|
raise ValueError('Appending failed')
|
||||||
|
|
||||||
|
|
||||||
|
def develop(path=sys.argv[-1]):
|
||||||
|
podofo = get_podofo()
|
||||||
|
p = podofo.PDFDoc()
|
||||||
|
p.open(path)
|
||||||
|
p.title = 'test'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
get_xmp_metadata(sys.argv[-1])
|
develop()
|
||||||
|
@ -739,9 +739,9 @@ static PdfDictionary&
|
|||||||
get_or_create_info(PDFDoc *self) {
|
get_or_create_info(PDFDoc *self) {
|
||||||
PdfObject *info = self->doc->GetTrailer().GetDictionary().FindKey("Info");
|
PdfObject *info = self->doc->GetTrailer().GetDictionary().FindKey("Info");
|
||||||
if (info && info->IsDictionary()) return info->GetDictionary();
|
if (info && info->IsDictionary()) return info->GetDictionary();
|
||||||
auto ninfo = self->doc->GetObjects().CreateDictionaryObject();
|
info = &self->doc->GetObjects().CreateDictionaryObject();
|
||||||
self->doc->GetTrailer().GetDictionary().AddKeyIndirect("Info", ninfo);
|
self->doc->GetTrailer().GetDictionary().AddKeyIndirect("Info", *info);
|
||||||
return ninfo.GetDictionary();
|
return info->GetDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline PyObject*
|
static inline PyObject*
|
||||||
@ -797,32 +797,62 @@ string_metadata_setter(PDFDoc *self, const std::string_view name, PyObject *val)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_title_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_title_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Title", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Title", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_author_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_author_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Author", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Author", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_subject_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_subject_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Subject", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Subject", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_keywords_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_keywords_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Keywords", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Keywords", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_creator_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_creator_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Creator", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Creator", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PDFDoc_producer_setter(PDFDoc *self, PyObject *val, void *closure) {
|
PDFDoc_producer_setter(PDFDoc *self, PyObject *val, void *closure) {
|
||||||
return string_metadata_setter(self, "Producer", val);
|
try {
|
||||||
|
return string_metadata_setter(self, "Producer", val);
|
||||||
|
} catch(const PdfError & err) {
|
||||||
|
podofo_set_exception(err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyGetSetDef PDFDoc_getsetters[] = {
|
static PyGetSetDef PDFDoc_getsetters[] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user