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 "PdfEncryptSession.h"
13
14namespace PoDoFo {
15
16class PdfParser;
17class PdfEncryptSession;
18
35class PODOFO_API PdfMemDocument final : public PdfDocument
36{
37 PODOFO_PRIVATE_FRIEND(class PdfWriter);
38
39public:
43
44 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
45
46 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
47
51
61 void Load(const std::string_view& filename, const std::string_view& password);
62 void Load(const std::string_view& filename, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
63
70 void LoadFromBuffer(const bufferview& buffer, const std::string_view& password);
71 void LoadFromBuffer(const bufferview& buffer, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
72
79 void Load(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
80 void Load(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
89 void Save(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
90
97 void Save(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
98
117 void SaveUpdate(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
118
129 void SaveUpdate(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
130
144 void SetEncrypted(const std::string_view& userPassword, const std::string_view& ownerPassword,
145 PdfPermissions protection = PdfPermissions::Default,
146 PdfEncryptionAlgorithm algorithm = PdfEncryptionAlgorithm::AESV3R6,
147 PdfKeyLength keyLength = PdfKeyLength::Unknown);
148
153 void SetEncrypt(std::unique_ptr<PdfEncrypt>&& encrypt);
154
155 bool HasOwnerPermissions() const override;
156
157 const PdfEncrypt* GetEncrypt() const override;
158
159 inline size_t GetMagicOffset() const { return m_MagicOffset; }
160
161 inline bool HasBrokenXRef() const { return m_HasBrokenXRef; }
162
163protected:
168 void SetPdfVersion(PdfVersion version) override;
169
170 PdfVersion GetPdfVersion() const override;
171
172private:
173 PdfMemDocument(bool empty);
174
175private:
176 void loadFromDevice(std::shared_ptr<InputStreamDevice>&& device, PdfLoadOptions opts, const std::string_view& password);
177
182 void initFromParser(PdfParser& parser);
183
186 void clear() override;
187
188 void reset() override;
189
190 void beforeWrite(PdfSaveOptions options);
191
192private:
193 PdfMemDocument& operator=(const PdfMemDocument&) = delete;
194
195private:
196 PdfVersion m_Version;
197 PdfVersion m_InitialVersion;
198 bool m_HasXRefStream;
199 bool m_HasBrokenXRef;
200 size_t m_MagicOffset;
201 size_t m_PrevXRefOffset;
202 std::unique_ptr<PdfEncryptSession> m_Encrypt;
203 std::shared_ptr<InputStreamDevice> m_device;
204};
205
206};
207
208
209#endif // PDF_MEM_DOCUMENT_H
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:109
A class that is used to encrypt a PDF file and set document permissions on the PDF file.
Definition PdfEncrypt.h:116
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition PdfMemDocument.h:36
void LoadFromBuffer(const bufferview &buffer, const std::string_view &password)
Load a PdfMemDocument from a buffer in memory.
void Save(const std::string_view &filename, PdfSaveOptions opts=PdfSaveOptions::None)
Save the complete document to a file.
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 a PdfRefCountedInputDevice.
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:35
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfEncryptionAlgorithm
The encryption algorithm.
Definition PdfEncrypt.h:86
PdfSaveOptions
Definition PdfDeclarations.h:467
PdfLoadOptions
Definition PdfDeclarations.h:505
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:16
PdfPermissions
Set user permissions/restrictions on a document.
Definition PdfEncrypt.h:62
PdfKeyLength
A enum specifying a valid keylength for a PDF encryption key.
Definition PdfEncrypt.h:39