]> mj.ucw.cz Git - paperjam.git/commitdiff
Produce proper Info dictionary
authorMartin Mares <mj@ucw.cz>
Sat, 7 Apr 2018 08:22:39 +0000 (10:22 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 7 Apr 2018 08:22:39 +0000 (10:22 +0200)
pdf.cc

diff --git a/pdf.cc b/pdf.cc
index d54506e6d669071b1771fcb1a45d96dda6d19afc..8f46d1674c5ecf112583f9955026058c2a008015 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -109,6 +109,32 @@ vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &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<cmd *> &cmds)
 {
   debug("### Reading input");
@@ -160,17 +186,7 @@ void process(list<cmd *> &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);