[poppler] utils/pdfunite.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jan 8 23:26:34 UTC 2017


 utils/pdfunite.cc |   33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

New commits:
commit 3cae7773d2f8ad6506e2712689c56fa6975e01d3
Author: Thomas Freitag <Thomas.Freitag at alfa.de>
Date:   Mon Jan 9 00:25:53 2017 +0100

    pdfunite: add fields to AcroForm dict
    
    Bug #99141

diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index 19a1eb5..dfe48bf 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -4,7 +4,7 @@
 //
 // This file is licensed under the GPLv2 or later
 //
-// Copyright (C) 2011-2015 Thomas Freitag <Thomas.Freitag at alfa.de>
+// Copyright (C) 2011-2015, 2017 Thomas Freitag <Thomas.Freitag at alfa.de>
 // Copyright (C) 2012 Arseny Solokha <asolokha at gmx.com>
 // Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
 // Copyright (C) 2012, 2014 Albert Astals Cid <aacid at kde.org>
@@ -164,6 +164,26 @@ void doMergeNameDict(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldRefNum,
   }
 }
 
+void doMergeFormDict(Dict *srcFormDict, Dict *mergeFormDict, int numOffset) {
+  Object srcFields, mergeFields;
+
+  srcFormDict->lookup("Fields", &srcFields);
+  mergeFormDict->lookup("Fields", &mergeFields);
+  if (srcFields.isArray() && mergeFields.isArray()) {
+    for (int i = 0; i < mergeFields.arrayGetLength(); i++) {
+      Object value;
+      Object *newValue = new Object();
+      mergeFields.arrayGetNF(i, &value);
+      newValue->initRef(value.getRef().num + numOffset, value.getRef().gen);
+      srcFields.arrayAdd(newValue);
+      value.free();
+      delete newValue;
+    }
+  }
+  srcFields.free();
+  mergeFields.free();
+}
+
 ///////////////////////////////////////////////////////////////////////////
 int main (int argc, char *argv[])
 ///////////////////////////////////////////////////////////////////////////
@@ -360,7 +380,7 @@ int main (int argc, char *argv[])
         annotsObj.free();
       }
     }
-    Object pageCatObj, pageNames;
+    Object pageCatObj, pageNames, pageForm;
     docs[i]->getXRef()->getCatalog(&pageCatObj);
     Dict *pageCatDict = pageCatObj.getDict();
     pageCatDict->lookup("Names", &pageNames);
@@ -371,6 +391,15 @@ int main (int argc, char *argv[])
       }
       doMergeNameDict(docs[i], yRef, countRef, 0, 0, names.getDict(), pageNames.getDict(), numOffset);
     }
+    pageCatDict->lookup("AcroForm", &pageForm);
+    if (i > 0 && !pageForm.isNull() && pageForm.isDict()) {
+      if (afObj.isNull()) {
+        pageCatDict->lookupNF("AcroForm", &afObj);
+      } else if (afObj.isDict()) {
+        doMergeFormDict(afObj.getDict(), pageForm.getDict(), numOffset);
+      }
+    }
+    pageForm.free();
     pageNames.free();
     pageCatObj.free();
     objectsCount += docs[i]->writePageObjects(outStr, yRef, numOffset, gTrue);


More information about the poppler mailing list