3#ifndef PDFSDK_CXX_PDF_DOCUMENT_H_INCLUDED_
4#define PDFSDK_CXX_PDF_DOCUMENT_H_INCLUDED_
14#include <pdfsdk/cxx/bytes.h>
15#include <pdfsdk/cxx/math.h>
16#include <pdfsdk/cxx/progress_monitor.h>
18#include "forward_declarations.h"
20#include "wrapper_base.h"
27class Document :
public detail::RefCountedHandle<PDDoc> {
38 const std::wstring& password = std::wstring());
52 const std::wstring& password = std::wstring());
65 const std::wstring& password = std::wstring());
139 void Save(
const std::filesystem::path& path,
221 void InsertPages(
size_t insertAt,
const Document& sourceDoc,
const std::vector<size_t>& sourcePageIndexes = {},
ProgressMonitor* mon =
nullptr);
490 template<
class EnumProc>
570 std::span<const FormField> fields = std::span<const FormField>(),
571 bool exclude =
true);
585 bool exclude =
true);
598 std::span<const FormField> fields = std::span<const FormField>(),
599 bool exclude =
true);
640 std::span<const FormField> fields = std::span<const FormField>(),
641 bool exclude =
true);
655 bool exclude =
true);
668 std::span<const FormField> fields = std::span<const FormField>(),
669 bool exclude =
true);
721 void ResetForm(std::span<const FormField> fields = std::span<const FormField>(),
722 PDResetFormFlags flags = kPDResetFormFlagExclude);
959 template<
class EnumProc>
989 template<
class EnumProc>
1554 PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Document, PDDoc)
1559#include "document_impl.inl"
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
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.
std::vector< Byte > ExportFormFDFToMemory(std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values to an in-memory Forms Data Format (FDF) buffer.
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 group at the specified index.
Action GetDocLevelJSAction(std::string_view name) const
Gets the document-level JavaScript action with the specified name.
void ImportFormXFDFFromMemory(std::span< const Byte > data)
Imports form field values from an in-memory XFDF (XML Forms Data Format) buffer.
std::vector< Byte > ExportFormXFDFToMemory(std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values to an in-memory XFDF (XML Forms Data Format) buffer.
void ImportFormXFDFFromStream(IDataSource &source)
Imports form field values from an XFDF byte source.
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.
OutputIntent GetOutputIntent(size_t index) const
Gets an Output Intent by index.
FileSpec CreateEmbeddedFile(const std::wstring &path)
Creates an embedded file with the specified path.
void SetInfoString(PDAtom infoDictKey, const std::wstring &infoValue)
Sets the information string associated with the specified info string atom.
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())
Opens a PDF file from the specified path.
uint64_t GetFileSize() const
Gets the file size of the document.
Annot CreateLinkAnnot(const RectF &rect, Action action)
Creates a link annotation with the specified rectangle and action.
bool IsCompressed() const
Checks if the document is compressed.
void ExportFormFDF(const std::filesystem::path &path, std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values to a Forms Data Format (FDF) file.
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.
void ImportFormFDF(const std::filesystem::path &path)
Imports form field values from a Forms Data Format (FDF) file.
void RemoveStructTree()
Removes the document's logical structure tree.
OCConfig GetOCAltConfig(size_t index) const
Gets the alternate optional content configuration at the given index.
Action CreateActionGoToR(const FileSpec &fileSpec, size_t pageIndex)
Creates a GoToR action with the specified file specification and page 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 SaveToStream(IWriteSink &sink, PDDocSaveFlags flags=kPDDocSaveFull|kPDDocSaveCompressed, ProgressMonitor *progmon=nullptr, const PDOptSaveSettings *optSettings=nullptr, const PDVersion *version=nullptr)
Saves the document to a caller-supplied sink.
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.
void AddOutputIntent(const OutputIntent &oi)
Adds an Output Intent to the document.
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.
PDVersion GetFileVersion() const
Gets the PDF version of the document.
Object GetInfoObject() const
Gets the info object of the document.
size_t GetNumOCAltConfigs() const
Gets the number of alternate optional content configurations.
OCGroup CreateOCGroup(const std::wstring &name)
Creates an optional content 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 groups in the document.
void ExportFormXFDF(const std::filesystem::path &path, std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values to an XFDF (XML Forms Data Format) file.
bool IsRepaired() const
Allows to check if the document was repaired during the opening process.
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.
void ImportFormFDFFromStream(IDataSource &source)
Imports form field values from an FDF byte source.
void RemoveSecurity()
Removes any security handler and encryption applied to the document.
bool IsEncrypted() const
Checks if the document is encrypted.
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.
std::string GetXmpMetadata() const
Gets full XMP metadata packet for document.
void SetOpenAction(Action action)
Sets the open action for the document.
void EnumDocLevelJSActions(EnumProc enumProc) const
Enumerates the document-level JavaScript actions.
FileSpec GetAttachment(std::string_view name) const
Gets the attachment with the specified name.
void RemoveAttachment(std::string_view name)
Removes the attachment with the specified name.
Object GetRootObject() const
Gets the root object of the document.
Object CreateActionFieldsData(std::span< const FormField > fields)
Creates an action fields-data object referencing the given form fields.
PDPageDirection GetPageDirection() const
Gets the page direction of the document.
static Document OpenDocumentFromMemory(std::span< const Byte > data, bool copy=false, const std::wstring &password=std::wstring())
Opens a PDF file from a memory buffer.
void DeletePage(size_t index)
Deletes the page at the specified index.
void SetOCConfig(const OCConfig &config)
Sets the document's default optional content configuration.
Object CreateNameObject(PDAtom value, bool indirect=false)
Creates a name object.
void ResetForm(std::span< const FormField > fields=std::span< const FormField >(), PDResetFormFlags flags=kPDResetFormFlagExclude)
Resets form fields to their default values.
void DeletePages(const std::vector< size_t > &pageIndexes, ProgressMonitor *mon=nullptr)
Deletes the pages within the specified range.
Action CreateActionHide()
Creates a Hide action.
PDDateTime GetModDate() const
Gets the modification date of the document.
void AddAttachment(std::string_view name, FileSpec filespec)
Adds an attachment to the document.
void EnumFonts(EnumProc enumProc, ProgressMonitor *mon=nullptr) const
Enumerates the fonts used in the document.
bool IsTaggedPDF() const
Checks if the PDF document is a tagged PDF.
Page GetPage(size_t index) const
Gets the page at the specified index.
Font CreateFontFromInfo(const PDFontInfo &fontInfo, bool forceSysFont=true, PDEFontCreateFlags createFlags=kPDEFontCreateFlagsDefault)
Creates a font in the document using the specified font information.
static Document NewDocument(const RectF &mediaBox=RectF(0.0f, 792.0f, 612.0f, 0.0f))
Creates a new PDF document.
XObject ImportIcon(const Document &source, size_t pageIndex=0)
Imports an icon from another document.
Font ConvertFontToType0(const Font &font, PDEFontCreateFlags createFlags=kPDEFontCreateFlagsDefault)
Creates a Type0 (composite) equivalent of the specified font. The result can be used in place of the ...
void ImportFormFDFFromMemory(std::span< const Byte > data)
Imports form field values from an in-memory Forms Data Format (FDF) buffer.
size_t GetNumOutputIntents() const
Gets the number of Output Intents in the document.
PDFAFlavor GetPDFAFlavor() const
Gets the PDF/A flavor of the document according to its XMP metadata.
PDAtom GetPageLayout() const
Gets the page layout of the document.
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.
void SetXmpMetadata(const std::string &xmpPacket)
Sets XMP metadata packet for document.
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 ExportFormXFDFToStream(IWriteSink &sink, std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values as XFDF to a caller-supplied byte sink.
void ImportFormXFDF(const std::filesystem::path &path)
Imports form field values from an XFDF (XML Forms Data Format) file.
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.
Font CreateFontEmbeddedCopy(const Font &font, PDEFontCreateFlags createFlags=kPDEFontCreateFlagsDefault)
Creates an embedded copy of the specified font in the document.
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.
StructTreeRoot CreateStructTree()
Creates a logical structure tree for the document.
StructTreeRoot GetStructTree() const
Gets the document's logical structure tree.
std::string GetAttachmentNameByIndex(size_t index) const
Gets the name of the attachment at the specified index.
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.
Annot CreateFileAttachmentAnnot(const FileSpec &fileSpec, const RectF &rect)
Creates a file attachment annotation with the specified file specification and rectangle....
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.
Annot CreatePopupAnnot(const RectF &rect)
Creates a popup annotation with the specified rectangle.
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...
void RemoveOutputIntent(const OutputIntent &oi)
Removes an Output Intent from the document.
std::wstring GetInfoString(PDAtom infoDictKey) const
Gets the information string associated with the specified info string atom.
OCConfig GetOCConfig() const
Gets the document's default optional content configuration.
void ExportFormFDFToStream(IWriteSink &sink, std::span< const FormField > fields=std::span< const FormField >(), bool exclude=true)
Exports the form field values as FDF to a caller-supplied byte sink.
static Document OpenDocumentFromStream(std::shared_ptr< IDataSource > source, const std::wstring &password=std::wstring())
Opens a PDF file from a caller-supplied data source.
void Save(const std::filesystem::path &path, PDDocSaveFlags flags=kPDDocSaveFull|kPDDocSaveCompressed, ProgressMonitor *progmon=nullptr, const PDOptSaveSettings *optSettings=nullptr, const PDVersion *version=nullptr)
Saves the document to a file.
Object CreateStreamObject(std::span< const Byte > data, const Object &attributesDict, const Object &encodeParms, bool encodeSource)
Creates a stream object.
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:30
A callback interface for supplying bytes from a random-access source.
Definition io_stream.h:19
A callback interface for receiving bytes written sequentially.
Definition io_stream.h:43
Optional content configuration.
Definition optional_content.h:160
Optional content group (OCG).
Definition optional_content.h:24
Represents a PDF object.
Definition object.h:25
Defines the Output Intent information.
Definition output_intent.h:22
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 from PDF objects.
Definition read_stream.h:19
Represents a shading in a PDF document.
Definition shading.h:18
The root of a document's logical structure (tag) tree.
Definition struct_tree.h:400
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:536
@ kPDEFontCreateFlagsDefault
Definition content.h:811
PDETilingPatternPaintType
Specifies the type of tiling pattern.
Definition content.h:515
PDPageDirection
Specifies the logical content order of text.
Definition document.h:204
@ kPDDocSaveFull
Definition document.h:117
@ kPDDocSaveCompressed
Definition document.h:124
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
Helper class that represents the data of the Standard Security Handler.
Definition standard_security.h:34
Specifies the font information.
Definition fonts.h:36
Definition document.h:166