PoDoFo  1.0.0-dev
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 "PdfExtension.h"
15 #include "PdfEncryptSession.h"
16 
17 namespace PoDoFo {
18 
19 class PdfParser;
20 class PdfEncryptSession;
21 
38 class PODOFO_API PdfMemDocument final : public PdfDocument
39 {
40  PODOFO_PRIVATE_FRIEND(class PdfWriter);
41 
42 public:
46 
47  PdfMemDocument(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password = { });
48 
51  PdfMemDocument(const PdfMemDocument& rhs);
52 
62  void Load(const std::string_view& filename, const std::string_view& password = { });
63 
70  void LoadFromBuffer(const bufferview& buffer, const std::string_view& password = { });
71 
78  void Load(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password = { });
79 
88  void Save(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
89 
96  void Save(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
97 
116  void SaveUpdate(const std::string_view& filename, PdfSaveOptions opts = PdfSaveOptions::None);
117 
128  void SaveUpdate(OutputStreamDevice& device, PdfSaveOptions opts = PdfSaveOptions::None);
129 
134  void AddPdfExtension(const PdfName& ns, int64_t level);
135 
141  bool HasPdfExtension(const std::string_view& ns, int64_t level) const;
142 
147  void RemovePdfExtension(const std::string_view& ns, int64_t level);
148 
153  std::vector<PdfExtension> GetPdfExtensions() const;
154 
168  void SetEncrypted(const std::string_view& userPassword, const std::string_view& ownerPassword,
169  PdfPermissions protection = PdfPermissions::Default,
171  PdfKeyLength keyLength = PdfKeyLength::L128);
172 
177  void SetEncrypt(std::unique_ptr<PdfEncrypt>&& encrypt);
178 
179  const PdfEncrypt* GetEncrypt() const override;
180 
181 protected:
186  void SetPdfVersion(PdfVersion version) override;
187 
188  PdfVersion GetPdfVersion() const override;
189 
190 private:
191  PdfMemDocument(bool empty);
192 
193 private:
194  void loadFromDevice(const std::shared_ptr<InputStreamDevice>& device, const std::string_view& password);
195 
200  void initFromParser(PdfParser& parser);
201 
204  void clear() override;
205 
206  void reset() override;
207 
208  void beforeWrite(PdfSaveOptions options);
209 
210 private:
211  PdfMemDocument& operator=(const PdfMemDocument&) = delete;
212 
213 private:
214  PdfVersion m_Version;
215  PdfVersion m_InitialVersion;
216  bool m_HasXRefStream;
217  int64_t m_PrevXRefOffset;
218  std::unique_ptr<PdfEncryptSession> m_Encrypt;
219  std::shared_ptr<InputStreamDevice> m_device;
220 };
221 
222 };
223 
224 
225 #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:122
PdfMemDocument is the core class for reading and manipulating PDF files and writing them back to disk...
Definition: PdfMemDocument.h:39
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.
This class represents a PdfName.
Definition: PdfName.h:24
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:90
@ AESV2
AES encryption with a 128 bit key (PDF1.6)
PdfSaveOptions
Definition: PdfDeclarations.h:440
cspan< char > bufferview
Convenient read-only char buffer span.
Definition: basetypes.h:19
PdfPermissions
Set user permissions/restrictions on a document.
Definition: PdfEncrypt.h:66
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