Commit 26556636 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos
Browse files

Add saveWithoutChangesAs method to be able to save the document ignoring...

Add saveWithoutChangesAs method to be able to save the document ignoring changes made in forms or annots
parent 2a39932a
......@@ -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)
{
......
......@@ -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);
......
......@@ -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;
......
......@@ -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; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment