![]() |
#include <PDFDoc.h>
Public Member Functions | |
PDFDoc () | |
Default constructor. | |
PDFDoc (SDF::SDFDoc &sdfdoc) | |
Create a PDF document from an existing SDF/Cos document. | |
PDFDoc (const UString &filepath) | |
Open an existing PDF document. | |
PDFDoc (const char *filepath) | |
PDFDoc (Filters::Filter stream) | |
Open an existing PDF document. | |
PDFDoc (const char *buf, size_t buf_size) | |
Open a SDF/Cos document from a memory buffer. | |
~PDFDoc () | |
Destructor. | |
bool | IsEncrypted () |
bool | InitSecurityHandler (void *custom_data=0) |
Initializes document's SecurityHandler. | |
bool | InitStdSecurityHandler (const char *password, int password_sz=0) |
Initializes document's SecurityHandler using the supplied password. | |
SDF::SecurityHandler | GetSecurityHandler () |
void | SetSecurityHandler (SDF::SecurityHandler handler) |
The function sets a new SecurityHandler as the current security handler. | |
void | RemoveSecurity () |
This function removes document security. | |
PDFDocInfo | GetDocInfo () |
PDFDocViewPrefs | GetViewPrefs () |
bool | IsModified () const |
Call this function to determine whether the document has been modified since it was last saved. | |
bool | IsLinearized () const |
Call this function to determine whether the document is represented in linearized (fast web view) format. | |
void | Save (const UString &path, UInt32 flags, Common::ProgressMonitor *progress) |
Saves the document to a file. | |
void | Save (const char *&out_buf, size_t &out_buf_size, UInt32 flags, Common::ProgressMonitor *progress) |
Saves the document to a memory buffer. | |
PageIterator | GetPageIterator (UInt32 page_number=1) |
Page | GetPage (UInt32 page_number) |
void | PageRemove (const PageIterator &page_itr) |
void | PageInsert (PageIterator &where, Page page) |
Insert/Import a single page at a specific location in the page sequence. | |
void | PagePushFront (Page page) |
Adds a page to the beginning of a document's page sequence. | |
void | PagePushBack (Page page) |
Adds a page to the end of a document's page sequence. | |
std::vector< Page > | ImportPages (const std::vector< Page > &pages, bool import_bookmarks=false) |
The function imports a list of pages to this document. | |
Page | PageCreate (const Rect &media_box=Rect(0, 0, 612, 792)) |
Create a new, empty page in the document. | |
class Bookmark | GetFirstBookmark () |
void | AddRootBookmark (class Bookmark root_bookmark) |
Adds/links the specified Bookmark to the root level of document’s outline tree. | |
SDF::Obj | GetTrailer () |
SDF::Obj | GetRoot () |
SDF::Obj | GetPages () |
int | GetPageCount () |
FieldIterator | GetFieldIterator () |
An interactive form (sometimes referred to as an AcroForm) is a collection of fields for gathering information interactively from the user. | |
FieldIterator | GetFieldIterator (const UString &field_name) |
Field | GetField (const UString &field_name) |
field_name - a string representing the fully qualified name of the field (e.g. | |
Field | FieldCreate (const UString &field_name, Field::Type type, SDF::Obj field_value=0, SDF::Obj def_field_value=0) |
Create a new interactive form Field. | |
Field | FieldCreate (const UString &field_name, Field::Type type, const UString &field_value, const UString &def_field_value) |
void | RefreshFieldAppearances () |
Regenerates the appearance stream for every widget annotation in the document Call this method if you modified field's value and would like to update field's appearances. | |
void | FlattenFields () |
Flatten all form fields in the document. | |
SDF::Obj | GetAcroForm () |
FDF::FDFDoc | FDFExtract () |
void | FDFMerge (FDF::FDFDoc &fdf_doc) |
Import form data from FDF file to PDF interactive form. | |
Action | GetOpenAction () |
void | SetOpenAction (const Action &action) |
Sets the Action that will be triggered when the document is opened. | |
void | AddFileAttachment (const char *file_key, FileSpec embedded_file) |
Associates a file attachment with the document. | |
PageLabel | GetPageLabel (int page_num) |
void | SetPageLabel (int page_num, PageLabel &label) |
Attaches a label to a page. | |
void | RemovePageLabel (int page_num) |
Removes the page label that is attached to the specified page, effectively merging the specified range with the previous page label sequence. | |
bool | IsTagged () |
Struct::STree | GetStructTree () |
bool | HasOC () const |
SDF::Obj | GetOCGs () const |
OCG::Config | GetOCGConfig () const |
void | AddHighlights (const UString &hilite) |
AddHighlights is used to highlight text in a document using 'Adobe's Highlight File Format' (Technical Note #5172 ). | |
SDF::Obj | CreateIndirectName (const char *name) |
The following list of methods is used to create SDF/Cos indirect objects. | |
SDF::Obj | CreateIndirectArray () |
SDF::Obj | CreateIndirectBool (bool value) |
SDF::Obj | CreateIndirectDict () |
SDF::Obj | CreateIndirectNull () |
SDF::Obj | CreateIndirectNumber (double value) |
SDF::Obj | CreateIndirectString (const UChar *value, UInt32 size) |
SDF::Obj | CreateIndirectString (const UString &str) |
SDF::Obj | CreateIndirectStream (Filters::FilterReader &data, Filters::Filter filter_chain=Filters::Filter(0, false)) |
SDF::Obj | CreateIndirectStream (const char *data, const size_t data_size, Filters::Filter filter_chain=Filters::Filter(0, false)) |
SDF::SDFDoc & | GetSDFDoc () |
operator SDF::SDFDoc & () | |
Explicit conversion operator from PDFDoc to SDF::Doc. | |
void | Lock () |
Locks the document to prevent competing threads from accessing the document at the same time. | |
void | Unlock () |
Removes the lock from the document. | |
bool | IsLocked () |
bool | TryLock (int milliseconds=0) |
Try locking the document, waiting no longer than specified number of milliseconds. | |
UString | GetFileName () const |
Most applications using PDFNet will use this class to open existing PDF documents, or to create new PDF documents from scratch.
The class offers a number of entry points into the document. For example,
The class also offers utility methods to slit and merge PDF pages, to create new pages, to flatten forms, to change security settings, etc.
pdftron::PDF::PDFDoc::PDFDoc | ( | ) |
Default constructor.
Creates an empty new document.
pdftron::PDF::PDFDoc::PDFDoc | ( | SDF::SDFDoc & | sdfdoc | ) |
pdftron::PDF::PDFDoc::PDFDoc | ( | const UString & | filepath | ) |
Open an existing PDF document.
filepath | - pathname to the file. |
pdftron::PDF::PDFDoc::PDFDoc | ( | const char * | filepath | ) |
pdftron::PDF::PDFDoc::PDFDoc | ( | Filters::Filter | stream | ) |
Open an existing PDF document.
stream | - input stream containing a serialized document. The input stream may be a random-access file, memory buffer, slow HTTP connection etc. |
Make sure to call InitSecurityHandler() after PDFDoc(...) for encrypted documents.
pdftron::PDF::PDFDoc::PDFDoc | ( | const char * | buf, | |
size_t | buf_size | |||
) |
Open a SDF/Cos document from a memory buffer.
the buffer ownership is not transfered to the document so the user should clean-up any allocated memory if necessary.
buf | - a memory buffer containing the serialized document | |
buf_size | - the size of memory buffer. |
pdftron::PDF::PDFDoc::~PDFDoc | ( | ) |
Destructor.
bool pdftron::PDF::PDFDoc::IsEncrypted | ( | ) |
bool pdftron::PDF::PDFDoc::InitSecurityHandler | ( | void * | custom_data = 0 |
) |
Initializes document's SecurityHandler.
This version of InitSecurityHandler() works with Standard and Custom PDF security and can be used in situations where the password is obtained dynamically via user feedback. See EncTest sample for example code.
This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted.
If the security handler was successfully initialized it can be later obtained using GetSecurityHandler() method.
An | exception is thrown if the matching handler for document's security was not found in the global SecurityManager. In this case, you need to register additional custom security handlers with the global SecurityManager (using SecurityManagerSingleton). |
custom_data | An optional parameter used to specify custom data that should be passed in SecurityHandler::Initialize() callback. |
bool pdftron::PDF::PDFDoc::InitStdSecurityHandler | ( | const char * | password, | |
int | password_sz = 0 | |||
) |
Initializes document's SecurityHandler using the supplied password.
This version of InitSecurityHandler() assumes that document uses Standard security and that a password is specified directly.
This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted.
If the security handler was successfully initialized, it can be later obtained using GetSecurityHandler() method.
An | exception is thrown if the document's security Filter is not 'Standard'. In this case, you need to register additional custom security handlers with the global SecurityManager (SecurityManagerSingleton). |
password | Specifies the password used to open the document without any user feedback. If you would like to dynamically obtain the password, you need to derive a custom class from StdSecurityHandler() and use InitSecurityHandler() without any parameters. See EncTest sample for example code. | |
password_len | An optional parameter used to specify the size of the password buffer, in bytes. If the 'password_sz' is 0, or if the parameter is not specified, the function assumes that the string is null terminated. |
SDF::SecurityHandler pdftron::PDF::PDFDoc::GetSecurityHandler | ( | ) |
Returned security handler can be modified in order to change the security settings of the existing document. Changes to the current handler will not invalidate the access to the original file and will take effect during document Save().
If the security handler is modified, document will perform a full save even if e_incremental was given as a flag in Save() method.
void pdftron::PDF::PDFDoc::SetSecurityHandler | ( | SDF::SecurityHandler | handler | ) |
The function sets a new SecurityHandler as the current security handler.
- | new SecurityHandler |
void pdftron::PDF::PDFDoc::RemoveSecurity | ( | ) |
This function removes document security.
PDFDocInfo pdftron::PDF::PDFDoc::GetDocInfo | ( | ) |
PDFDocViewPrefs pdftron::PDF::PDFDoc::GetViewPrefs | ( | ) |
bool pdftron::PDF::PDFDoc::IsModified | ( | ) | const |
Call this function to determine whether the document has been modified since it was last saved.
bool pdftron::PDF::PDFDoc::IsLinearized | ( | ) | const |
Call this function to determine whether the document is represented in linearized (fast web view) format.
To save a document in linearized (fast web view) format you only need to pass 'Doc.SaveOptions.e_linearized' flag in the Save method.
void pdftron::PDF::PDFDoc::Save | ( | const UString & | path, | |
UInt32 | flags, | |||
Common::ProgressMonitor * | progress | |||
) |
Saves the document to a file.
If a full save is requested to the original path, the file is saved to a file system-determined temporary file, the old file is deleted, and the temporary file is renamed to path.
A full save with remove unused or linearization option may re-arrange object in the cross reference table. Therefore all pointers and references to document objects and resources should be re acquired in order to continue document editing.
In order to use incremental save the specified path must match original path and e_incremental flag bit should be set.
path | - The full path name to which the file is saved. | |
flags | - A bit field composed of an OR of Doc::SaveOptions values. | |
progress | - A pointer to the progress interface. NULL if progress tracking is not required. |
- | if the file can't be opened for saving or if there is a problem during Save an Exception object will be thrown. |
void pdftron::PDF::PDFDoc::Save | ( | const char *& | out_buf, | |
size_t & | out_buf_size, | |||
UInt32 | flags, | |||
Common::ProgressMonitor * | progress | |||
) |
Saves the document to a memory buffer.
out_buf | a pointer to the buffer containing the serialized version of the document. (C++ Note) The buffer is owned by a document and the client doesn't need to do any initialization or cleanup. | |
out_buf_size | the size of the serialized document (i.e. out_buf) in bytes. | |
flags | - A bit field composed of an OR of Doc::SaveOptions values. Note that this method ignores e_incremental flag. | |
progress | - A pointer to the progress interface. NULL if progress tracking is not required. |
- | if there is a problem during Save an Exception object will be thrown. |
PageIterator pdftron::PDF::PDFDoc::GetPageIterator | ( | UInt32 | page_number = 1 |
) |
PageIterator itr = pdfdoc.GetPageIterator(); while (itr.HasNext()) { // Read every page Page page = itr.Current(); // ... itr.Next() }
page_number | - the page number in document's page sequence. Page numbers in document's page sequence are indexed from 1. |
Page page = pdfdoc.GetPage(page_num); if (page == null) return; // Page not found
void pdftron::PDF::PDFDoc::PageRemove | ( | const PageIterator & | page_itr | ) |
page_itr | - the PageIterator to the page that should be removed A PageIterator for the given page can be obtained using PDFDoc::Find(page_num) or using direct iteration through document's page sequence. |
void pdftron::PDF::PDFDoc::PageInsert | ( | PageIterator & | where, | |
Page | page | |||
) |
Insert/Import a single page at a specific location in the page sequence.
where | - The location in the page sequence indicating where to insert the page. The page is inserted before the specified location. | |
page | - A page to insert. |
void pdftron::PDF::PDFDoc::PagePushFront | ( | Page | page | ) |
Adds a page to the beginning of a document's page sequence.
page | - a page to prepend to the document Invalidates all PageIterators pointing to the document. |
void pdftron::PDF::PDFDoc::PagePushBack | ( | Page | page | ) |
Adds a page to the end of a document's page sequence.
page | - a page to append to the document |
std::vector<Page> pdftron::PDF::PDFDoc::ImportPages | ( | const std::vector< Page > & | pages, | |
bool | import_bookmarks = false | |||
) |
The function imports a list of pages to this document.
Although a list of pages can be imported using repeated calls to PageInsert(), PageImport will not import duplicate copies of resources that are shared across pages (such as fonts, images, colorspaces etc). Therefore this method is recommended when a page import list consists of several pages that share the same resources.
pages | A list of pages to import. All pages should belong to the same source document. | |
import_bookmarks | An optional flag specifying whether any bookmark items pointing to pages in the import list should be merged with the target (i.e. this) document. |
Create a new, empty page in the document.
You can use PageWriter to fill the page with new content. Finally the page should be inserted at specific place within document page sequence using PageInsert/PagePushFront/PagePushBack methods.
media_box | A rectangle, expressed in default user space units, defining the boundaries of the physical medium on which the page is intended to be displayed or printed. A user space units is 1/72 of an inch. If media_box is not specified the default dimensions of the page are 8.5 x 11 inches (or 8.5*72, 11*72 units). |
The following is a listing of some standard U.S. page sizes:
The following is a listing of ISO standard page sizes:
class Bookmark pdftron::PDF::PDFDoc::GetFirstBookmark | ( | ) |
void pdftron::PDF::PDFDoc::AddRootBookmark | ( | class Bookmark | root_bookmark | ) |
Adds/links the specified Bookmark to the root level of document’s outline tree.
SDF::Obj pdftron::PDF::PDFDoc::GetTrailer | ( | ) |
SDF::Obj pdftron::PDF::PDFDoc::GetRoot | ( | ) |
SDF::Obj pdftron::PDF::PDFDoc::GetPages | ( | ) |
int pdftron::PDF::PDFDoc::GetPageCount | ( | ) |
FieldIterator pdftron::PDF::PDFDoc::GetFieldIterator | ( | ) |
An interactive form (sometimes referred to as an AcroForm) is a collection of fields for gathering information interactively from the user.
A PDF document may contain any number of fields appearing on any combination of pages, all of which make up a single, global interactive form spanning the entire document.
The following methods are used to access and manipulate Interactive form fields (sometimes referred to as AcroForms).
FieldIterator itr = pdfdoc.GetFieldIterator(); for(; itr.HasNext(); itr.Next()) { Field field = itr.Current(); Console.WriteLine("Field name: {0}", field.GetName()); }
For a full sample, please refer to 'InteractiveForms' sample project.
FieldIterator pdftron::PDF::PDFDoc::GetFieldIterator | ( | const UString & | field_name | ) |
field_name - a string representing the fully qualified name of the field (e.g.
"employee.name.first").
FieldIterator itr = pdfdoc.FieldFind("name"); if (itr.HasNext()) { Console.WriteLine("Field name: {0}", itr.Current().GetName()); } else { ...field was not found... }
Field pdftron::PDF::PDFDoc::FieldCreate | ( | const UString & | field_name, | |
Field::Type | type, | |||
SDF::Obj | field_value = 0 , |
|||
SDF::Obj | def_field_value = 0 | |||
) |
Create a new interactive form Field.
field_name | a string representing the fully qualified name of the field (e.g. "employee.name.first"). field_name must be either a unique name or equal to an existing terminal field name. | |
type | field type (e.g. Field::e_text, Field::e_button, etc.) | |
field_value | ||
def_field_value |
if | 'field_name' is equal to an existing non-terminal field name an exception is thrown. |
Field pdftron::PDF::PDFDoc::FieldCreate | ( | const UString & | field_name, | |
Field::Type | type, | |||
const UString & | field_value, | |||
const UString & | def_field_value | |||
) |
void pdftron::PDF::PDFDoc::RefreshFieldAppearances | ( | ) |
Regenerates the appearance stream for every widget annotation in the document Call this method if you modified field's value and would like to update field's appearances.
void pdftron::PDF::PDFDoc::FlattenFields | ( | ) |
Flatten all form fields in the document.
Please refer to documentation for PDF::Field for more information about form flattening.
SDF::Obj pdftron::PDF::PDFDoc::GetAcroForm | ( | ) |
FDF::FDFDoc pdftron::PDF::PDFDoc::FDFExtract | ( | ) |
void pdftron::PDF::PDFDoc::FDFMerge | ( | FDF::FDFDoc & | fdf_doc | ) |
Action pdftron::PDF::PDFDoc::GetOpenAction | ( | ) |
void pdftron::PDF::PDFDoc::SetOpenAction | ( | const Action & | action | ) |
void pdftron::PDF::PDFDoc::AddFileAttachment | ( | const char * | file_key, | |
FileSpec | embedded_file | |||
) |
Associates a file attachment with the document.
The file attachment will be displayed in the user interface of a viewer application (in Acrobat this is File Attachment tab). The function differs from Annot.CreateFileAttachment() because it associates the attachment with the whole document instead of an annotation on a specific page.
file_key | A key/name under which the attachment will be stored. | |
embedded_file | Embedded file stream |
SDF::NameTree names = SDF::NameTree::Create(doc, "EmbeddedFiles"); names.Put(file_key, file_keysz, embedded_file.GetSDFObj());
PageLabel pdftron::PDF::PDFDoc::GetPageLabel | ( | int | page_num | ) |
void pdftron::PDF::PDFDoc::SetPageLabel | ( | int | page_num, | |
PageLabel & | label | |||
) |
Attaches a label to a page.
This establishes the numbering scheme for that page and all following it, until another page label is encountered. This label allows PDF producers to define a page numbering system other than the default.
page_num | The number of the page to label. If page_num is less than 1 or greater than the number of pages in the document, the method does nothing. |
void pdftron::PDF::PDFDoc::RemovePageLabel | ( | int | page_num | ) |
Removes the page label that is attached to the specified page, effectively merging the specified range with the previous page label sequence.
page_num | The page from which the page label is removed. Because PDFNet indexes pages starting from 1, page_num must be larger than 0. |
bool pdftron::PDF::PDFDoc::IsTagged | ( | ) |
Struct::STree pdftron::PDF::PDFDoc::GetStructTree | ( | ) |
bool pdftron::PDF::PDFDoc::HasOC | ( | ) | const |
SDF::Obj pdftron::PDF::PDFDoc::GetOCGs | ( | ) | const |
OCG::Config pdftron::PDF::PDFDoc::GetOCGConfig | ( | ) | const |
void pdftron::PDF::PDFDoc::AddHighlights | ( | const UString & | hilite | ) |
AddHighlights is used to highlight text in a document using 'Adobe's Highlight File Format' (Technical Note #5172 ).
The method will parse the character offset data and modify the current document by adding new highlight annotations.
hilite | a string representing the filename for the highlight file or or a data buffer containing XML data. |
An | exception will be thrown if the XML file is malformed or os out of sync with the document. |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectName | ( | const char * | name | ) |
The following list of methods is used to create SDF/Cos indirect objects.
Unlike direct objects, indirect objects can be referenced by more than one object (i.e. indirect objects they can be shared).
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectArray | ( | ) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectBool | ( | bool | value | ) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectDict | ( | ) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectNull | ( | ) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectNumber | ( | double | value | ) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectStream | ( | Filters::FilterReader & | data, | |
Filters::Filter | filter_chain = Filters::Filter(0, false) | |||
) |
SDF::Obj pdftron::PDF::PDFDoc::CreateIndirectStream | ( | const char * | data, | |
const size_t | data_size, | |||
Filters::Filter | filter_chain = Filters::Filter(0, false) | |||
) |
SDF::SDFDoc& pdftron::PDF::PDFDoc::GetSDFDoc | ( | ) |
pdftron::PDF::PDFDoc::operator SDF::SDFDoc & | ( | ) | [inline] |
Explicit conversion operator from PDFDoc to SDF::Doc.
References GetSDFDoc().
void pdftron::PDF::PDFDoc::Lock | ( | ) |
Locks the document to prevent competing threads from accessing the document at the same time.
Threads attempting to access the document will wait in suspended state until the thread that owns the lock calls doc.Unlock().
void pdftron::PDF::PDFDoc::Unlock | ( | ) |
Removes the lock from the document.
bool pdftron::PDF::PDFDoc::IsLocked | ( | ) |
bool pdftron::PDF::PDFDoc::TryLock | ( | int | milliseconds = 0 |
) |
Try locking the document, waiting no longer than specified number of milliseconds.
UString pdftron::PDF::PDFDoc::GetFileName | ( | ) | const |