PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfMemDocument.h
1// SPDX-FileCopyrightText: 2006 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
3// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
4
5#ifndef PDF_MEM_DOCUMENT_H
6#define PDF_MEM_DOCUMENT_H
7
8#include <podofo/auxiliary/InputDevice.h>
9#include <podofo/auxiliary/OutputDevice.h>
10
11#include "PdfDocument.h"
12#include "PdfEncrypt.h"
13
14namespace PoDoFo {
15
16class PdfParser;
17class PdfEncryptSession;
18
34class PODOFO_API PdfMemDocument final : public PdfDocument
35{
36 PODOFO_PRIVATE_FRIEND(class PdfWriter);
37
38public:
41
42 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
43
44 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
45
48
50
57 void Load(const std::string_view& filename, const std::string_view& password);
58
66 void Load(const std::string_view& filename, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
67
74 void LoadFromBuffer(const bufferview& buffer, const std::string_view& password);
75
83 void LoadFromBuffer(const bufferview& buffer, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
84
91 void Load(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
92
100 void Load(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
109 void Save(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
110
117 void Save(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
118
137 void SaveUpdate(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
138
149 void SaveUpdate(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
150
163 void SetEncrypted(const std::string_view& userPassword, const std::string_view& ownerPassword,
164 PdfPermissions protection = PdfPermissions::Default,
165 PdfEncryptionAlgorithm algorithm = PdfEncryptionAlgorithm::AESV3R6,
166 PdfKeyLength keyLength = PdfKeyLength::Unknown);
167
171 void SetEncrypt(std::unique_ptr<PdfEncrypt>&& encrypt);
172
173 bool HasOwnerPermissions() const override;
174
175 const PdfEncrypt* GetEncrypt() const override;
176
177 inline size_t GetMagicOffset() const { return m_MagicOffset; }
178
179 inline bool HasBrokenXRef() const { return m_HasBrokenXRef; }
180
181protected:
185 void SetPdfVersion(PdfVersion version) override;
186
187 PdfVersion GetPdfVersion() const override;
188
189private:
190 PdfMemDocument(bool empty);
191
192private:
193 void loadFromDevice(std::shared_ptr<InputStreamDevice>&& device, PdfLoadOptions opts, const std::string_view& password);
194
198 void initFromParser(PdfParser& parser);
199
201 void clear() override;
202
203 void reset() override;
204
205 void beforeWrite(PdfSaveOptions options, bool isUpdate);
206
209 void pruneCompressedObjectStreams(PdfSaveOptions options);
210
211private:
212 PdfMemDocument& operator=(const PdfMemDocument&) = delete;
213
214private:
215 PdfVersion m_Version;
216 PdfVersion m_InitialVersion;
217 bool m_HasXRefStream;
218 bool m_HasBrokenXRef;
219 bool m_initiallyEncrypted;
220 size_t m_MagicOffset;
221 size_t m_PrevXRefOffset;
222 std::unique_ptr<PdfEncryptSession> m_Encrypt;
223 std::shared_ptr<InputStreamDevice> m_device;
224};
225
226};
227
228
229#endif // PDF_MEM_DOCUMENT_H
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
A class that is used to encrypt a PDF file and set document permissions on the PDF file.
Definition PdfEncrypt.h:113
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition PdfMemDocument.h:35
void LoadFromBuffer(const bufferview &buffer, const std::string_view &password)
Load a PdfMemDocument from a buffer in memory.
void Load(std::shared_ptr< InputStreamDevice > device, PdfLoadOptions opts=PdfLoadOptions::None, const std::string_view &password={ })
Load a PdfMemDocument from an input device.
void Load(const std::string_view &filename, PdfLoadOptions opts=PdfLoadOptions::None, const std::string_view &password={ })
Load a PdfMemDocument from a file.
void Save(const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
Save the complete document to a file.
void LoadFromBuffer(const bufferview &buffer, PdfLoadOptions opts=PdfLoadOptions::None, const std::string_view &password={ })
Load a PdfMemDocument from a buffer in memory.
void Load(const std::string_view &filename, const std::string_view &password)
Load a PdfMemDocument from a file.
void Load(std::shared_ptr< InputStreamDevice > device, const std::string_view &password)
Load a PdfMemDocument from an input device.
void SaveUpdate(const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
Save the document changes to a file.
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfLoadOptions
Definition PdfDeclarations.h:468
PdfEncryptionAlgorithm
The encryption algorithm.
Definition PdfEncrypt.h:82
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:15
PdfPermissions
Set user permissions/restrictions on a document.
Definition PdfEncrypt.h:60
PdfSaveOptions
Definition PdfDeclarations.h:429
PdfKeyLength
A enum specifying a valid keylength for a PDF encryption key.
Definition PdfEncrypt.h:38