PoDoFo 1.0.0-dev
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(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password = { });
47
51
61 void Load(const std::string_view& filename, const std::string_view& password = { });
62
69 void LoadFromBuffer(const bufferview& buffer, const std::string_view& password = { });
70
77 void Load(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password = { });
78
87 void Save(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
88
95 void Save(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
96
115 void SaveUpdate(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
116
127 void SaveUpdate(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
128
142 void SetEncrypted(const std::string_view& userPassword, const std::string_view& ownerPassword,
143 PdfPermissions protection = PdfPermissions::Default,
144 PdfEncryptionAlgorithm algorithm = PdfEncryptionAlgorithm::AESV3R6,
145 PdfKeyLength keyLength = PdfKeyLength::Unknown);
146
151 void SetEncrypt(std::unique_ptr<PdfEncrypt>&& encrypt);
152
153 const PdfEncrypt* GetEncrypt() const override;
154
155protected:
160 void SetPdfVersion(PdfVersion version) override;
161
162 PdfVersion GetPdfVersion() const override;
163
164private:
165 PdfMemDocument(bool empty);
166
167private:
168 void loadFromDevice(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password);
169
174 void initFromParser(PdfParser& parser);
175
178 void clear() override;
179
180 void reset() override;
181
182 void beforeWrite(PdfSaveOptions options);
183
184private:
185 PdfMemDocument& operator=(const PdfMemDocument&) = delete;
186
187private:
188 PdfVersion m_Version;
189 PdfVersion m_InitialVersion;
190 bool m_HasXRefStream;
191 int64_t m_PrevXRefOffset;
192 std::unique_ptr<PdfEncryptSession> m_Encrypt;
193 std::shared_ptr<InputStreamDevice> m_device;
194};
195
196};
197
198
199#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 Load(const std::shared_ptr< InputStreamDevice > &device, const std::string_view &password={ })
Load a PdfMemDocument from a PdfRefCountedInputDevice.
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 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
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