PoDoFo 1.1.0
Loading...
Searching...
No Matches
PdfMemDocument.h
1
7#ifndef PDF_MEM_DOCUMENT_H
8#define PDF_MEM_DOCUMENT_H
9
10#include <podofo/auxiliary/InputDevice.h>
11#include <podofo/auxiliary/OutputDevice.h>
12
13#include "PdfDocument.h"
14#include "PdfEncryptSession.h"
15
16namespace PoDoFo {
17
18class PdfParser;
19class PdfEncryptSession;
20
37class PODOFO_API PdfMemDocument final : public PdfDocument
38{
39 PODOFO_PRIVATE_FRIEND(class PdfWriter);
40
41public:
45
46 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
47
48 PdfMemDocument(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
49
53
63 void Load(const std::string_view& filename, const std::string_view& password);
64 void Load(const std::string_view& filename, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
65
72 void LoadFromBuffer(const bufferview& buffer, const std::string_view& password);
73 void LoadFromBuffer(const bufferview& buffer, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
74
81 void Load(std::shared_ptr<InputStreamDevice> device, const std::string_view& password);
82 void Load(std::shared_ptr<InputStreamDevice> device, PdfLoadOptions opts = PdfLoadOptions::None, const std::string_view& password = { });
91 void Save(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
92
99 void Save(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
100
119 void SaveUpdate(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
120
131 void SaveUpdate(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
132
146 void SetEncrypted(const std::string_view& userPassword, const std::string_view& ownerPassword,
147 PdfPermissions protection = PdfPermissions::Default,
148 PdfEncryptionAlgorithm algorithm = PdfEncryptionAlgorithm::AESV3R6,
149 PdfKeyLength keyLength = PdfKeyLength::Unknown);
150
155 void SetEncrypt(std::unique_ptr<PdfEncrypt>&& encrypt);
156
157 const PdfEncrypt* GetEncrypt() const override;
158
159protected:
164 void SetPdfVersion(PdfVersion version) override;
165
166 PdfVersion GetPdfVersion() const override;
167
168private:
169 PdfMemDocument(bool empty);
170
171private:
172 void loadFromDevice(std::shared_ptr<InputStreamDevice>&& device, PdfLoadOptions opts, const std::string_view& password);
173
178 void initFromParser(PdfParser& parser);
179
182 void clear() override;
183
184 void reset() override;
185
186 void beforeWrite(PdfSaveOptions options);
187
188private:
189 PdfMemDocument& operator=(const PdfMemDocument&) = delete;
190
191private:
192 PdfVersion m_Version;
193 PdfVersion m_InitialVersion;
194 bool m_HasXRefStream;
195 int64_t m_PrevXRefOffset;
196 std::unique_ptr<PdfEncryptSession> m_Encrypt;
197 std::shared_ptr<InputStreamDevice> m_device;
198};
199
200};
201
202
203#endif // PDF_MEM_DOCUMENT_H
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
A class that is used to encrypt a PDF file and set document permissions on the PDF file.
Definition PdfEncrypt.h:118
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition PdfMemDocument.h:38
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:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfEncryptionAlgorithm
The encryption algorithm.
Definition PdfEncrypt.h:88
PdfSaveOptions
Definition PdfDeclarations.h:469
PdfLoadOptions
Definition PdfDeclarations.h:501
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:19
PdfPermissions
Set user permissions/restrictions on a document.
Definition PdfEncrypt.h:64
PdfKeyLength
A enum specifying a valid keylength for a PDF encryption key.
Definition PdfEncrypt.h:41
PdfVersion
Enum to identify different versions of the PDF file format.
Definition PdfDeclarations.h:71