PDF SDK Documentation

Comprehensive Guide for Developers: Features, Integration, and API Reference

Loading...
Searching...
No Matches
document.h
1// Copyright (c) 2009-2025 Avanquest Software. All rights reserved.
2
3#ifndef PDFSDK_CXX_PDF_DOCUMENT_H_INCLUDED_
4#define PDFSDK_CXX_PDF_DOCUMENT_H_INCLUDED_
5
6#include <filesystem>
7#include <string>
8
9#include <pdfsdk/core/types.h>
10#include <pdfsdk/cxx/math.h>
11#include <pdfsdk/cxx/progress_monitor.h>
12
13#include "forward_declarations.h"
14#include "standard_security.h"
15#include "wrapper_base.h"
16
17namespace PDF {
18
22class Document : public detail::RefCountedHandle<PDDoc> {
23public:
29
39 static Document OpenDocument(const std::filesystem::path& path, const std::wstring& password = std::wstring());
40
52 static Document OpenDocument(const void* data, size_t size, bool copy = false, const std::wstring& password = std::wstring());
53
58 bool IsCompressed() const;
59
64 bool IsModified() const;
65
70 void SetModified(bool modified);
71
76 std::filesystem::path GetFilePath() const;
77
97 void Save(const std::filesystem::path& path,
98 PDDocSaveFlags flags = kPDDocSaveFull | kPDDocSaveCompressed,
99 ProgressMonitor* progmon = nullptr,
100 const PDOptSaveSettings* optSettings = nullptr,
101 const PDVersion* version = nullptr);
102
107 size_t GetNumPages() const;
108
114 Page GetPage(size_t index) const;
115
123 Page CreatePage(size_t insertAt, const RectF& mediaBox);
124
132 void CreatePages(size_t insertAt, size_t count, const RectF& mediaBox);
133
141 void DeletePages(const std::vector<size_t>& pageIndexes, ProgressMonitor* mon = nullptr);
142
147 void DeletePage(size_t index);
148
157 void InsertPages(size_t insertAt, const Document& sourceDoc, const std::vector<size_t>& sourcePageIndexes = {}, ProgressMonitor* mon = nullptr);
158
164 void InsertPage(const Page& page, size_t insertAt);
165
174 void MovePages(size_t insertAt, const std::vector<size_t>& pageIndexes, ProgressMonitor* mon = nullptr);
175
185 std::wstring GetInfoString(PDAtom infoStringAtom) const;
186
197 void SetInfoString(PDAtom infoStringAtom, const std::wstring& string);
198
210
221 void SetCreationDate(const PDDateTime& date);
222
234
245 void SetModDate(const PDDateTime& date);
246
257 void SetPageLayout(PDAtom layout);
258
269 PDAtom GetPageLayout() const;
270
281 void SetPageMode(PDAtom mode);
282
293 PDAtom GetPageMode() const;
294
307
320
335
350 const RectF& bbox,
351 float xStep,
352 float yStep,
353 const Content& content);
354
362
376 Font CreateFontFromInfo(const PDFontInfo& fontInfo, bool forceSysFont = true, PDEFontCreateFlags createFlags = kPDEFontCreateEmbedded | kPDEFontCreateNeedSubset);
377
385 size_t GetNumFormFields() const;
386
395 FormField GetFormField(size_t index) const;
396
405
414
426 FormField CreateFormField(const std::wstring& fullname, PDAtom type, PDFieldFlags flags);
427
434 FormField FindFormField(const std::wstring& fullname) const;
435
442 void RenameFormField(FormField field, const std::wstring& fullname);
443
451 bool IsSigned() const;
452
459 void SaveSignedVersion(FormField sigField, const std::filesystem::path& path) const;
460
471 Action CreateActionURI(const std::string& uri);
472
484
494 Action CreateActionJavaScript(const std::wstring& jscode);
495
505 Action CreateActionSubmitForm(const std::string& serverUri);
506
516
526
538
546 void SetOpenAction(Action action);
547
553
567 Dest CreateDestXYZ(size_t pageIndex, const PointF& xy, float zoom, bool isRemote = false);
568
579 Dest CreateDestFit(size_t pageIndex, bool isRemote = false);
580
591 Dest CreateDestFitH(size_t pageIndex, float top, bool isRemote = false);
592
603 Dest CreateDestFitV(size_t pageIndex, float left, bool isRemote = false);
604
615 Dest CreateDestFitR(size_t pageIndex, const RectF& rect, bool isRemote = false);
616
626 Dest CreateDestFitB(size_t pageIndex, bool isRemote = false);
627
638 Dest CreateDestFitBH(size_t pageIndex, float top, bool isRemote = false);
639
650 Dest CreateDestFitBV(size_t pageIndex, float left, bool isRemote = false);
651
657
663
669 template<class EnumProc>
670 void EnumDocLevelJSActions(EnumProc enumProc) const;
671
678 Action GetDocLevelJSAction(const std::wstring& name) const;
679
684
692 FileSpec GetAttachment(const std::wstring& name) const;
693
699 template<class EnumProc>
700 void EnumAttachments(EnumProc enumProc) const;
701
708 void AddAttachment(const std::wstring& name, FileSpec filespec);
709
715 void RemoveAttachment(const std::wstring& name);
716
721 size_t GetNumAttachments() const;
722
728 std::wstring GetAttachmentNameByIndex(size_t index) const;
729
736 FileSpec CreateFileSpec(PDAtom fileSys, const std::wstring& path);
737
744 FileSpec CreateEmbeddedFile(const std::wstring& path);
745
755
764
775
788 OCGroup CreateOCGroup(const std::wstring& name);
789
799 size_t GetNumOCGroups() const;
800
811 OCGroup GetOCGroup(size_t index) const;
812
822
833 Annot CreateTextMarkupAnnot(PDAtom type, PDColorValue color, const QuadPoints& quads);
834
846 Annot CreateInkAnnot(PDColorValue color, float lineWidth, const std::vector<std::vector<PointF>>& points);
847
860
872 Annot CreateStampAnnot(const RectF& rect, const XObject& appearance);
873
884 Annot CreateWidgetAnnot(const FormField& field, const RectF& rect);
885
894 Object GetObjectByID(uint32_t id) const;
895
906
917
927 Object CreateBoolObject(bool value, bool indirect = false);
928
938 Object CreateIntObject(int64_t value, bool indirect = false);
939
949 Object CreateRealObject(float value, bool indirect = false);
950
961 Object CreateStringObjectUnicode(const std::wstring& unicode, bool indirect = false);
962
974 Object CreateStringObject(const std::string& bytes, bool hex = false, bool indirect = false);
975
987 Object CreateNameObject(PDAtom value, bool indirect = false);
988
999 Object CreateArrayObject(bool indirect);
1000
1012 Object CreateDictObject(bool indirect);
1013
1027 Object CreateStreamObject(const void* data, size_t size, const Object& attributesDict, const Object& encodeParms, bool encodeSource);
1028
1034 Object CopyObject(const Object& source);
1035
1045
1056
1066 void SetStandardSecurityParams(const StdSecurityParams& requestedParams);
1067
1076 bool RequestPermission(PDPermReqObj object, PDPermReqOp operation, const std::wstring& password = std::wstring()) const;
1077
1093 XObject ImportIcon(const Document& source, size_t pageIndex = 0);
1094
1105 void CreatePageFromIcon(size_t insertAt, const Document& iconDoc, const XObject& icon);
1106
1107 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Document, PDDoc)
1108};
1109
1110} // namespace PDF
1111
1112#include "document_impl.inl"
1113
1114#endif // PDFSDK_CXX_PDF_DOCUMENT_H_INCLUDED_
Represents an action in a PDF document.
Definition action.h:32
Represents an annotation in a PDF document.
Definition annot.h:24
Represents a bookmark/outline item in a PDF document.
Definition bookmark.h:33
Represents a content array.
Definition content.h:29
Represents a destination in a PDF document.
Definition dest.h:31
Represents a PDF document.
Definition document.h:22
Bookmark CreateRootBookmark()
Creates a root bookmark for the document.
Action CreateActionGoTo(Dest dest)
Creates a GoTo action with the specified destination.
Action GetOpenAction() const
Gets the open action of the document.
void AddAttachment(const std::wstring &name, FileSpec filespec)
Adds an attachment to the document.
Dest CreateDestFitV(size_t pageIndex, float left, bool isRemote=false)
Creates a destination that fits the height of the page.
Pattern CreatePatternShading(const Shading &shading)
Creates a pattern object in the document using the specified pattern shading. A shading pattern objec...
OCGroup GetOCGroup(size_t index) const
Gets the optional content (OC) group at the specified index.
std::wstring GetInfoString(PDAtom infoStringAtom) const
Gets the information string associated with the specified info string atom.
void MovePages(size_t insertAt, const std::vector< size_t > &pageIndexes, ProgressMonitor *mon=nullptr)
Moves pages within the document to a new position.
Object CreateStringObjectUnicode(const std::wstring &unicode, bool indirect=false)
Creates a literal string object from a Unicode string.
Annot CreateStampAnnot(const RectF &rect, const XObject &appearance)
Creates a (rubber) stamp annotation with the specified rectangle and appearance.
Object CreateRealObject(float value, bool indirect=false)
Creates a real number object.
void InsertPages(size_t insertAt, const Document &sourceDoc, const std::vector< size_t > &sourcePageIndexes={}, ProgressMonitor *mon=nullptr)
Inserts pages from another document into the current document.
FileSpec CreateEmbeddedFile(const std::wstring &path)
Creates an embedded file with the specified path.
void RemoveFormField(FormField field)
Removes the specified form field from the document.
static Document OpenDocument(const std::filesystem::path &path, const std::wstring &password=std::wstring())
A function to open a PDF file.
bool IsCompressed() const
Checks if the document is compressed.
Object CreateIntObject(int64_t value, bool indirect=false)
Creates an integer value object.
void CreatePages(size_t insertAt, size_t count, const RectF &mediaBox)
Creates multiple pages starting at the specified index with the given media box.
Object CreateDictObject(bool indirect)
Creates a dictionary object.
void RemoveDocLevelJS()
Removes the document-level JavaScript actions.
std::wstring GetAttachmentNameByIndex(size_t index) const
Gets the name of the attachment at the specified index.
FormField FindFormField(const std::wstring &fullname) const
Finds a form field with the specified full name.
Dest CreateDestXYZ(size_t pageIndex, const PointF &xy, float zoom, bool isRemote=false)
Creates a destination with XYZ coordinates and zoom level.
Pattern CreatePatternTiling(PDETilingPatternPaintType paintType, PDETilingPatternTilingType tilingType, const RectF &bbox, float xStep, float yStep, const Content &content)
Creates a pattern object in the document using the specified pattern paint type.
FormField CreateFormField(const std::wstring &fullname, PDAtom type, PDFieldFlags flags)
Creates a new form field with the specified name, type, and flags.
Dest CreateDestFitBH(size_t pageIndex, float top, bool isRemote=false)
Creates a destination that fits the width of the bounding box of the page.
void SetModDate(const PDDateTime &date)
Sets the modification date of the document.
std::filesystem::path GetFilePath() const
Gets the file path of the document.
Dest CreateDestFit(size_t pageIndex, bool isRemote=false)
Creates a destination that fits the entire page.
Action CreateActionJavaScript(const std::wstring &jscode)
Creates a JavaScript action with the specified JavaScript code.
size_t GetNumPages() const
Gets the number of pages in the document.
void SetPageLayout(PDAtom layout)
Sets the page layout of the document.
Dest CreateDestFitH(size_t pageIndex, float top, bool isRemote=false)
Creates a destination that fits the width of the page.
Object CreateBoolObject(bool value, bool indirect=false)
Creates a boolean value object.
Object GetInfoObject() const
Gets the info object of the document.
static Document NewDocument()
A function to create an empty PDF file.
OCGroup CreateOCGroup(const std::wstring &name)
Creates an optional content (OC) group with the specified name.
FormField GetFormField(size_t index) const
Gets the form field at the specified index.
size_t GetNumOCGroups() const
Gets the number of optional content (OC) groups in the document.
Action GetDocLevelJSAction(const std::wstring &name) const
Gets the document-level JavaScript action with the specified name.
void SetOpenDestination(Dest dest)
Sets the open destination for the document.
StdSecurityParams GetStandardSecurityParams() const
Gets the standard security parameters of the document.
Annot CreateTextAnnot(const RectF &rect)
Creates a text annotation with the specified dimensions.
Dest CreateDestFitBV(size_t pageIndex, float left, bool isRemote=false)
Creates a destination that fits the height of the bounding box of the page.
Annot CreateFreeTextAnnot(const RectF &rect)
Creates a free text annotation with the specified rectangle.
void SetOpenAction(Action action)
Sets the open action for the document.
Font CreateFontFromInfo(const PDFontInfo &fontInfo, bool forceSysFont=true, PDEFontCreateFlags createFlags=kPDEFontCreateEmbedded|kPDEFontCreateNeedSubset)
Creates a font in the document using the specified font information.
void EnumDocLevelJSActions(EnumProc enumProc) const
Enumerates the document-level JavaScript actions.
void SetInfoString(PDAtom infoStringAtom, const std::wstring &string)
Sets the information string associated with the specified info string atom.
Object GetRootObject() const
Gets the root object of the document.
PDPageDirection GetPageDirection() const
Gets the page direction of the document.
void DeletePage(size_t index)
Deletes the page at the specified index.
Object CreateNameObject(PDAtom value, bool indirect=false)
Creates a name object.
void DeletePages(const std::vector< size_t > &pageIndexes, ProgressMonitor *mon=nullptr)
Deletes the pages within the specified range.
Object CreateStreamObject(const void *data, size_t size, const Object &attributesDict, const Object &encodeParms, bool encodeSource)
Creates a stream object.
FileSpec GetAttachment(const std::wstring &name) const
Gets the attachment with the specified name.
Action CreateActionHide()
Creates a Hide action.
PDDateTime GetModDate() const
Gets the modification date of the document.
void RemoveAttachment(const std::wstring &name)
Removes the attachment with the specified name.
Page GetPage(size_t index) const
Gets the page at the specified index.
XObject ImportIcon(const Document &source, size_t pageIndex=0)
Imports an icon from another document.
PDAtom GetPageLayout() const
Gets the page layout of the document.
static Document OpenDocument(const void *data, size_t size, bool copy=false, const std::wstring &password=std::wstring())
A function to open a PDF file from a memory buffer.
Dest CreateDestFitR(size_t pageIndex, const RectF &rect, bool isRemote=false)
Creates a destination that fits the specified rectangle on the page.
Action CreateActionResetForm()
Creates a ResetForm action.
void CreatePageFromIcon(size_t insertAt, const Document &iconDoc, const XObject &icon)
Creates a page from an icon.
Action CreateActionNamed(PDAtom name)
Creates a Named action with the specified name.
Dest GetOpenDestination() const
Gets the open destination of the document.
PDAtom GetPageMode() const
Gets the page mode of the document.
size_t GetNumFormFields() const
Gets the number of form fields in the document.
void SetPageMode(PDAtom mode)
Sets the page mode of the document.
Annot CreateTextMarkupAnnot(PDAtom type, PDColorValue color, const QuadPoints &quads)
Creates a text markup annotation with the specified type, color, and quad points.
bool IsSigned() const
Checks if the document is signed.
void SetStandardSecurityParams(const StdSecurityParams &requestedParams)
Sets the standard security parameters of the document.
Annot CreateInkAnnot(PDColorValue color, float lineWidth, const std::vector< std::vector< PointF > > &points)
Creates an ink annotation with the specified color, line width, and points.
size_t GetNumAttachments() const
Gets the number of attachments in the document.
Object CreateStringObject(const std::string &bytes, bool hex=false, bool indirect=false)
Creates a string object from a byte string.
void SetModified(bool modified)
Sets the state of the document to modified.
void SaveSignedVersion(FormField sigField, const std::filesystem::path &path) const
Writes to a file the version of the document as it was at the time of signing.
void SetCreationDate(const PDDateTime &date)
Sets the creation date of the document.
Page CreatePage(size_t insertAt, const RectF &mediaBox)
Creates a new page at the specified index with the given media box.
FileSpec CreateFileSpec(PDAtom fileSys, const std::wstring &path)
Creates a FileSpec with the specified file system and path.
Bookmark GetRootBookmark() const
Gets the root bookmark of the document.
Action CreateActionSubmitForm(const std::string &serverUri)
Creates a SubmitForm action with the specified server URI.
void EnumAttachments(EnumProc enumProc) const
Enumerates the attachments in the document.
void InsertPage(const Page &page, size_t insertAt)
Inserts a page at the specified index.
Object GetObjectByID(uint32_t id) const
Gets the indirect object with the specified ID.
void SetPageDirection(PDPageDirection direction)
Sets the page direction of the document.
Action CreateActionURI(const std::string &uri)
Creates a URI action with the specified URI.
PDDateTime GetCreationDate() const
Gets the creation date of the document.
Object CopyObject(const Object &source)
Copies an object.
void AddFormField(FormField field)
Adds a form field to the document.
void RenameFormField(FormField field, const std::wstring &fullname)
Renames a specified form field.
bool IsModified() const
Checks if the document has been modified.
bool RequestPermission(PDPermReqObj object, PDPermReqOp operation, const std::wstring &password=std::wstring()) const
Requests permission to perform an operation on the document. Permissions can be set either by the doc...
OCConfig GetOCConfig() const
Gets the optional content (OC) configuration of the document.
void Save(const std::filesystem::path &path, PDDocSaveFlags flags=kPDDocSaveFull|kPDDocSaveCompressed, ProgressMonitor *progmon=nullptr, const PDOptSaveSettings *optSettings=nullptr, const PDVersion *version=nullptr)
A function to save a PDF file.
Annot CreateWidgetAnnot(const FormField &field, const RectF &rect)
Creates a widget annotation for the specified form field.
XObject CreateFormXObject(const Content &content)
Creates a form XObject from the specified content stream.
Object CreateArrayObject(bool indirect)
Creates an array object.
Dest CreateDestFitB(size_t pageIndex, bool isRemote=false)
Creates a destination that fits the bounding box of the page.
ReadStream OpenXfaStream() const
Opens an XFA (XML Forms Architecture) stream.
Specifies an external file which is referred to inside a PDF document.
Definition filespec.h:29
Represents a font in a PDF document.
Definition font.h:21
Represents a form field in a PDF document.
Definition form_field.h:71
Optional content configuration.
Definition optional_content.h:98
Optional content group.
Definition optional_content.h:20
Represents a PDF object.
Definition object.h:20
Represents a leaf node (Page Object).
Definition page.h:20
Represents a shading or tiling pattern in a PDF document.
Definition pattern.h:18
Progress monitor for tracking the progress of an operation.
Definition progress_monitor.h:14
Represents a read stream for reading data.
Definition read_stream.h:15
Represents a shading in a PDF document.
Definition shading.h:17
Represents an XObject in a PDF document.
Definition xobject.h:22
PDETilingPatternTilingType
For a tiling pattern - specifies the type of tiling spacing.
Definition content.h:487
@ kPDEFontCreateNeedSubset
Definition content.h:717
@ kPDEFontCreateEmbedded
Definition content.h:712
PDETilingPatternPaintType
Specifies the type of tiling pattern.
Definition content.h:466
PDPageDirection
Specifies the logical content order of text.
Definition document.h:203
@ kPDDocSaveFull
Definition document.h:116
@ kPDDocSaveCompressed
Definition document.h:123
PDPermReqObj
Specifies the type of object to check permissions for.
Definition security.h:33
PDPermReqOp
Specifies the operation to check permissions for.
Definition security.h:61
Standard Security API.
Definition types.h:23
Definition math.h:154
Definition math.h:1195
Definition math.h:749
Helper class that represents the data of the Standard Security Handler.
Definition standard_security.h:34
Definition fonts.h:32
Definition document.h:165
Definition document.h:19
Common types.