2
* Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "poppler-embedded-file.h"
21
#include "poppler-embedded-file-private.h"
22
#include "poppler-private.h"
28
using namespace poppler;
30
embedded_file_private::embedded_file_private(EmbFile *ef)
35
embedded_file_private::~embedded_file_private()
40
embedded_file* embedded_file_private::create(EmbFile *ef)
42
return new embedded_file(*new embedded_file_private(ef));
46
\class poppler::embedded_file poppler-embedded-file.h "poppler/cpp/poppler-embedded-file.h"
48
Represents a file embedded in a PDF %document.
52
embedded_file::embedded_file(embedded_file_private &dd)
58
Destroys the embedded file.
60
embedded_file::~embedded_file()
66
\returns whether the embedded file is valid
68
bool embedded_file::is_valid() const
70
return d->emb_file->isOk();
74
\returns the name of the embedded file
76
std::string embedded_file::name() const
78
return std::string(d->emb_file->name()->getCString());
82
\returns the description of the embedded file
84
ustring embedded_file::description() const
86
return detail::unicode_GooString_to_ustring(d->emb_file->description());
90
\note this is not always available in the PDF %document, in that case this
93
\returns the size of the embedded file, if known
95
int embedded_file::size() const
97
return d->emb_file->size();
101
\returns the time_t representing the modification date of the embedded file,
104
time_type embedded_file::modification_date() const
106
return detail::convert_date(d->emb_file->modDate()->getCString());
110
\returns the time_t representing the creation date of the embedded file,
113
time_type embedded_file::creation_date() const
115
return detail::convert_date(d->emb_file->createDate()->getCString());
119
\returns the checksum of the embedded file
121
byte_array embedded_file::checksum() const
123
GooString *cs = d->emb_file->checksum();
124
const char *ccs = cs->getCString();
125
byte_array data(cs->getLength());
126
for (int i = 0; i < cs->getLength(); ++i) {
133
\returns the MIME type of the embedded file, if available
135
std::string embedded_file::mime_type() const
137
return std::string(d->emb_file->mimeType()->getCString());
141
Reads all the data of the embedded file.
143
\returns the data of the embedded file
145
byte_array embedded_file::data() const
151
Stream *stream = d->emb_file->streamObject().getStream();
153
byte_array ret(1024);
156
while ((i = stream->getChar()) != EOF) {
157
if (data_len == ret.size()) {
158
ret.resize(ret.size() * 2);
160
ret[data_len] = (char)i;
163
ret.resize(data_len);