From 3a5ad8c5718ee91e3efb286a312d1134c35313c9 Mon Sep 17 00:00:00 2001 From: Jakub Kucharski Date: Tue, 23 Feb 2016 18:24:11 +0100 Subject: [PATCH 3/7] cpp: Added functions to save a document --- cpp/poppler-document.cpp | 30 ++++++++++++++++++++++++++++++ cpp/poppler-document.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp index 3b2c066..ead6a30 100644 --- a/cpp/poppler-document.cpp +++ b/cpp/poppler-document.cpp @@ -597,6 +597,36 @@ std::vector document::embedded_files() const } /** + Saves the %document to file \p file_name. + + \returns true on success, false on failure + */ +bool document::save(const std::string &file_name) const +{ + if (d->is_locked) { + return false; + } + + GooString fname(file_name.c_str()); + return d->doc->saveAs(&fname) == errNone; +} + +/** + Saves the original version of the %document to file \p file_name. + + \returns true on success, false on failure + */ +bool document::save_a_copy(const std::string &file_name) const +{ + if (d->is_locked) { + return false; + } + + GooString fname(file_name.c_str()); + return d->doc->saveWithoutChangesAs(&fname) == errNone; +} + +/** Tries to load a PDF %document from the specified file. \param file_name the file to open diff --git a/cpp/poppler-document.h b/cpp/poppler-document.h index dfae398..cd0d3bd 100644 --- a/cpp/poppler-document.h +++ b/cpp/poppler-document.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009-2010, Pino Toscano + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +82,9 @@ public: bool has_embedded_files() const; std::vector embedded_files() const; + bool save(const std::string &filename) const; + bool save_a_copy(const std::string &filename) const; + static document* load_from_file(const std::string &file_name, const std::string &owner_password = std::string(), const std::string &user_password = std::string()); -- 2.8.3