1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* Copyright (c) 2010 Glenn Rice <glennricster@gmail.com>
*
* This file is part of poppler-glibmm.
*
* poppler-glibmm is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 2.1 of the License,
* or (at your option) any later version.
*
* poppler-glibmm is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Poppler
{
Glib::RefPtr<Document> Document::new_from_data(const std::string& data, const std::string& password)
{
// poppler_document_new_from_data does not copy the data and the data must exist
// for the entire life of the document so we duplicate and store it here.
Glib::ScopedPtr<char> tmp_str;
*(tmp_str.addr()) = g_strdup(data.c_str());
GError* gerror = 0;
Glib::RefPtr<Document> retvalue = Glib::wrap(poppler_document_new_from_data(tmp_str.get(),
data.size(), password.c_str(), &gerror));
if(gerror)
::Glib::Error::throw_exception(gerror);
if (retvalue) std::swap(*(retvalue->m_PDFString.addr()), *(tmp_str.addr()));
return retvalue;
}
Glib::RefPtr<Document> Document::new_from_stream(const Glib::RefPtr<Gio::InputStream>& stream,
const goffset length, const std::string& password,
const Glib::RefPtr<Gio::Cancellable>& cancellable)
{
GError* gerror = 0;
Glib::RefPtr<Document> retvalue = Glib::wrap(poppler_document_new_from_stream(stream->gobj(),
length, password.c_str(), cancellable ? cancellable->gobj() : NULL, &gerror));
if(gerror)
::Glib::Error::throw_exception(gerror);
return retvalue;
}
static Glib::RefPtr<Document> new_from_gio_file(const Glib::RefPtr<Gio::File>& file,
const std::string& password,
const Glib::RefPtr<Gio::Cancellable>& cancellable)
{
GError* gerror = 0;
Glib::RefPtr<Document> retvalue = Glib::wrap(poppler_document_new_from_gfile(file->gobj(),
password.c_str(), cancellable ? cancellable->gobj() : NULL, &gerror));
if(gerror)
::Glib::Error::throw_exception(gerror);
return retvalue;
}
bool Document::get_id(Glib::ustring& permanent_id, Glib::ustring& update_id) const
{
Glib::ScopedPtr<gchar> permanent_id_array, update_id_array;
bool ret = poppler_document_get_id(const_cast<PopplerDocument*>(gobj()), permanent_id_array.addr(), update_id_array.addr());
if (ret)
{
permanent_id.assign(permanent_id_array.get(), permanent_id_array.get() + 32);
update_id.assign(update_id_array.get(), update_id_array.get() + 32);
}
return ret;
}
} // namespace Poppler
|