[poppler] 2 commits - glib/poppler-document.cc glib/poppler-document.h poppler/PDFDoc.cc poppler/PDFDoc.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sat Feb 9 04:15:34 PST 2008


 glib/poppler-document.cc |   41 ++++++++++++++++++++++++++++++++++++++++-
 glib/poppler-document.h  |    3 +++
 poppler/PDFDoc.cc        |   38 ++++++++++++++++++++++++++++++++------
 poppler/PDFDoc.h         |    4 ++++
 4 files changed, 79 insertions(+), 7 deletions(-)

New commits:
commit 5fb0c9d31c1abf2e6ad306c112fbd2a7c33d8772
Merge: 2655663... 2255c85...
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat Feb 9 13:15:15 2008 +0100

    Merge branch 'master' of ssh://carlosgc@git.freedesktop.org/git/poppler/poppler

commit 26556636e71d5abcbfdd1373f5576d1233532cf8
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat Feb 9 13:14:41 2008 +0100

    Add saveWithoutChangesAs method to be able to save the document ignoring changes made in forms or annots

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index a363b83..ef71db4 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -205,7 +205,9 @@ poppler_document_new_from_data (char        *data,
  * @uri: uri of file to save
  * @error: return location for an error, or %NULL
  * 
- * Saves @document.  If @error is set, %FALSE will be returned. Possible errors
+ * Saves @document. Any change made in the document such as 
+ * form fields filled by the user will be saved. 
+ * If @error is set, %FALSE will be returned. Possible errors
  * include those in the #G_FILE_ERROR domain.
  * 
  * Return value: %TRUE, if the document was successfully saved
@@ -233,6 +235,43 @@ poppler_document_save (PopplerDocument  *document,
   return retval;
 }
 
+/**
+ * poppler_document_save_a_copy:
+ * @document: a #PopplerDocument
+ * @uri: uri of file to save
+ * @error: return location for an error, or %NULL
+ * 
+ * Saves a copy of the original @document.
+ * Any change made in the document such as 
+ * form fields filled by the user will not be saved. 
+ * If @error is set, %FALSE will be returned. Possible errors
+ * include those in the #G_FILE_ERROR domain.
+ * 
+ * Return value: %TRUE, if the document was successfully saved
+ **/
+gboolean
+poppler_document_save_a_copy (PopplerDocument  *document,
+			      const char       *uri,
+			      GError          **error)
+{
+  char *filename;
+  gboolean retval = FALSE;
+
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), FALSE);
+
+  filename = g_filename_from_uri (uri, NULL, error);
+  if (filename != NULL) {
+    GooString *fname = new GooString (filename);
+    g_free (filename);
+
+    retval = document->doc->saveWithoutChangesAs (fname);
+
+    delete fname;
+  }
+
+  return retval;
+}
+
 static void
 poppler_document_finalize (GObject *object)
 {
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index 8d76231..1ff140e 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -104,6 +104,9 @@ PopplerDocument *poppler_document_new_from_data     (char             *data,
 gboolean         poppler_document_save              (PopplerDocument  *document,
 						     const char       *uri,
 						     GError          **error);
+gboolean         poppler_document_save_a_copy       (PopplerDocument  *document,
+						     const char       *uri,
+						     GError          **error);
 int              poppler_document_get_n_pages       (PopplerDocument  *document);
 PopplerPage     *poppler_document_get_page          (PopplerDocument  *document,
 						     int               index);
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 936e03b..c0c8f58 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -471,18 +471,44 @@ GBool PDFDoc::saveAs(OutStream *outStr, PDFWriteMode mode) {
       saveIncrementalUpdate(outStr);
     } else {
       // simply copy the original file
-      int c;
-      str->reset();
-      while ((c = str->getChar()) != EOF) {
-        outStr->put(c);
-      }
-      str->close();
+      saveWithoutChangesAs (outStr);
     }
   }
 
   return gTrue;
 }
 
+GBool PDFDoc::saveWithoutChangesAs(GooString *name) {
+  FILE *f;
+  OutStream *outStr;
+  GBool res;
+
+  if (!(f = fopen(name->getCString(), "wb"))) {
+    error(-1, "Couldn't open file '%s'", name->getCString());
+    return gFalse;
+  }
+  
+  outStr = new FileOutStream(f,0);
+  res = saveWithoutChangesAs(outStr);
+  delete outStr;
+
+  fclose(f);
+
+  return res;
+}
+
+GBool PDFDoc::saveWithoutChangesAs(OutStream *outStr) {
+  int c;
+  
+  str->reset();
+  while ((c = str->getChar()) != EOF) {
+    outStr->put(c);
+  }
+  str->close();
+
+  return gTrue;
+}
+
 void PDFDoc::saveIncrementalUpdate (OutStream* outStr)
 {
   XRef *uxref;
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index d411037..d6e4347 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -178,6 +178,10 @@ public:
   GBool saveAs(GooString *name, PDFWriteMode mode=writeStandard);
   // Save this file in the given output stream.
   GBool saveAs(OutStream *outStr, PDFWriteMode mode=writeStandard);
+  // Save this file with another name without saving changes
+  GBool saveWithoutChangesAs(GooString *name);
+  // Save this file in the given output stream without saving changes
+  GBool saveWithoutChangesAs(OutStream *outStr);
 
   // Return a pointer to the GUI (XPDFCore or WinPDFCore object).
   void *getGUIData() { return guiData; }


More information about the poppler mailing list