From: Martin Mares Date: Sat, 7 Apr 2018 08:22:39 +0000 (+0200) Subject: Produce proper Info dictionary X-Git-Tag: v0.1~5 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9544dddfa1d45a95fa9b6d8ee773c982256bd707;p=paperjam.git Produce proper Info dictionary --- diff --git a/pdf.cc b/pdf.cc index d54506e..8f46d16 100644 --- a/pdf.cc +++ b/pdf.cc @@ -109,6 +109,32 @@ vector run_command_list(list &cmds, vector &pages) return pages; } +static void make_info_dict() +{ + // Create info dictionary if it did not exist yet + QPDFObjectHandle trailer = out_pdf.getTrailer(); + QPDFObjectHandle info = trailer.getKey("/Info"); + if (info.isNull()) + { + info = QPDFObjectHandle::newDictionary(); + trailer.replaceKey("/Info", info); + } + else + assert(info.isDictionary()); + + info.replaceKey("/Producer", unicode_string("PaperJam")); + + // Copy entries from the source file's info dictionary + QPDFObjectHandle orig_trailer = in_pdf.getTrailer(); + QPDFObjectHandle orig_info = orig_trailer.getKey("/Info"); + if (!orig_info.isNull()) + { + const string to_copy[] = { "/Title", "/Author", "/Subject", "/Keywords", "/Creator", "/CreationDate" }; + for (string key: to_copy) + info.replaceOrRemoveKey(key, orig_info.getKey(key)); + } +} + void process(list &cmds) { debug("### Reading input"); @@ -160,17 +186,7 @@ void process(list &cmds) } // Produce info dictionary - QPDFObjectHandle trailer = out_pdf.getTrailer(); - QPDFObjectHandle info = trailer.getKey("/Info"); - if (info.isNull()) - { - info = QPDFObjectHandle::newDictionary(); - trailer.replaceKey("/Info", info); - } - else - assert(info.isDictionary()); - // FIXME: More meta-data - info.replaceKey("/Producer", unicode_string("PaperJam")); + make_info_dict(); // Write the output file QPDFWriter writer(out_pdf, out_name);