Class Document
This class represents a Document.
Inheritance
Namespace: PSPDFKit.Pdf
Assembly: PSPDFKit.dll
Syntax
public sealed class Document
Properties
DocumentSource
The DocumentSource of this Document
Declaration
public DocumentSource DocumentSource { get; }
Property Value
Type | Description |
---|---|
DocumentSource |
History
Gets History object once document is loaded, else returns null.
Declaration
public History History { get; }
Property Value
Type | Description |
---|---|
History |
Modified
Indicates if the document has been modified. Reset to false if the document has been saved.
Declaration
public bool Modified { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
ApplyRedactionsAsync()
Applies redactions to the current document. This will overwrite the opened file, removing content from the document irreversibly.
In the process of redacting the content, all the redaction annotations will be removed. Any annotation that is either partially or completely covered by a redaction annotation will be deleted.
Declaration
public IAsyncAction ApplyRedactionsAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
CloseDocumentAsync()
Close the document if the source is a file.
Declaration
public IAsyncAction CloseDocumentAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
CreateAnnotationAsync(IAnnotation)
Creates a new IAnnotation and assigns a local ID.
Declaration
public IAsyncOperation<IAnnotation> CreateAnnotationAsync(IAnnotation annotation)
Parameters
Type | Name | Description |
---|---|---|
IAnnotation | annotation | An annotation to be created on the document. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<IAnnotation> | The newly created IAnnotation. |
CreateAnnotationsAsync(IList<IAnnotation>)
Creates new annotations and assigns local IDs.
Declaration
public IAsyncOperation<IList<IAnnotation>> CreateAnnotationsAsync(IList<IAnnotation> annotations)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<IAnnotation> | annotations | A list of the IAnnotations to be created on the document |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IAnnotation>> | The newly created IAnnotations. |
CreateAttachmentAsync(IBuffer, String)
Creates a new attachment and returns it's ID.
Declaration
public IAsyncOperation<string> CreateAttachmentAsync(IBuffer attachment, string contentType)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.Streams.IBuffer | attachment | The buffer containing the attachment binary. |
System.String | contentType | The content type of the attachment. E.g. "image/png" |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.String> | An id representing the attachment in the document. |
CreateBookmarkAsync(Bookmark)
Add Bookmark to the document.
Declaration
public IAsyncOperation<Bookmark> CreateBookmarkAsync(Bookmark bookmark)
Parameters
Type | Name | Description |
---|---|---|
Bookmark | bookmark | The bookmark to be created. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Bookmark> | The created bookmark. |
CreateRedactionsBySearchAsync(SearchPattern, RedactionSearchOptions)
Searches the contents of the current document and creates Redaction annotations over matches.
See SearchPattern for a list of the supported patterns.
Notice that matches included when using one of the patterns might overfit the criteria (i.e. include false positive results). This might happen since we strive for including all positive results and avoid data loss. Make sure to review the matches found.
For searching for text or using regular expressions, see CreateRedactionsBySearchAsync(String, SearchType, RedactionSearchOptions)
Declaration
public IAsyncOperation<IEnumerable<string>> CreateRedactionsBySearchAsync(SearchPattern searchPattern, RedactionSearchOptions options)
Parameters
Type | Name | Description |
---|---|---|
SearchPattern | searchPattern | The preset pattern to use when searching. See SearchPattern for a list. |
RedactionSearchOptions | options | A RedactionSearchOptions object describing specific redaction options. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IEnumerable<System.String>> | A list containing the ids of the created redaction annotations. |
CreateRedactionsBySearchAsync(String, SearchType, RedactionSearchOptions)
Searches the contents of the current document and creates Redaction annotations over matches.
You can search for text, a regular expression, or use one of the default patterns we provide.
Regular expressions follow the ICU regular expression library.
For default presets, use CreateRedactionsBySearchAsync(SearchPattern, RedactionSearchOptions)
Declaration
[DefaultOverload]
public IAsyncOperation<IEnumerable<string>> CreateRedactionsBySearchAsync(string searchTerm, SearchType searchType, RedactionSearchOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.String | searchTerm | The term to search for. Can either be text or a regular expression. |
SearchType | searchType | |
RedactionSearchOptions | options | A RedactionSearchOptions object describing specific redaction options. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IEnumerable<System.String>> | A list containing the ids of the created redaction annotations. |
DeleteAnnotationAsync(String)
Deletes the IAnnotation specified by the ID.
Declaration
public IAsyncAction DeleteAnnotationAsync(string annotationId)
Parameters
Type | Name | Description |
---|---|---|
System.String | annotationId | An annotation to be deleted. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
DeleteBookmarkAsync(String)
Delete the named Bookmark from the document.
Declaration
public IAsyncAction DeleteBookmarkAsync(string bookmark)
Parameters
Type | Name | Description |
---|---|---|
System.String | bookmark | The bookmark to be deleted. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportAsync(StorageFile)
Export the document to a Windows.Storage.StorageFile
Declaration
public IAsyncAction ExportAsync(StorageFile file)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.StorageFile | file | The file into which the current state of the document will be saved |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportAsync(StorageFile, DocumentExportOptions)
Export the document to a Windows.Storage.StorageFile.
Declaration
public IAsyncAction ExportAsync(StorageFile file, DocumentExportOptions options)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.StorageFile | file | The file into which the current state of the document will be saved |
DocumentExportOptions | options | Advanced options for saving a processed document. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportInstantJsonAsync()
Return a representation of the current document state in Instant Json.
Declaration
public IAsyncOperation<JsonObject> ExportInstantJsonAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Windows.Data.Json.JsonObject> | A string holding the Instant Json information. |
ExportToDataSinkAsync(IDataSink, DocumentExportOptions)
Export the document to the IDataSink.
Declaration
public IAsyncAction ExportToDataSinkAsync(IDataSink dataSink, DocumentExportOptions options)
Parameters
Type | Name | Description |
---|---|---|
IDataSink | dataSink | The data sink that the document will be written to. |
DocumentExportOptions | options | Advanced options for saving a processed document. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportToDataWriterAsync(DataWriter, DocumentExportOptions)
Export the document to a Windows.Storage.Streams.DataWriter. Known issue: Caller must reopen document after exporting with this method.
Declaration
public IAsyncAction ExportToDataWriterAsync(DataWriter dataWriter, DocumentExportOptions options)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.Streams.DataWriter | dataWriter | The Windows.Storage.Streams.DataWriter into which the current state of the document will be written. |
DocumentExportOptions | options | Advanced options for saving a processed document. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportXfdfToDataSinkAsync(IDataSink)
Export current annotations to XFDF to a IDataSink.
Declaration
public IAsyncAction ExportXfdfToDataSinkAsync(IDataSink dataSink)
Parameters
Type | Name | Description |
---|---|---|
IDataSink | dataSink |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ExportXfdfToDataWriterAsync(DataWriter)
Export current annotations to XFDF to a Windows.Storage.Streams.DataWriter.
Declaration
public IAsyncAction ExportXfdfToDataWriterAsync(DataWriter dataWriter)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.Streams.DataWriter | dataWriter |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
GetAnnotationAttachmentAsync(String)
Gets the attachment associated with the Id
Declaration
public IAsyncOperation<Attachment> GetAnnotationAttachmentAsync(string id)
Parameters
Type | Name | Description |
---|---|---|
System.String | id | The id of the annotation attachment. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Attachment> | An Attachment |
GetAnnotationsAsync()
Gets IAnnotations for the whole document.
Declaration
public IAsyncOperation<IList<IAnnotation>> GetAnnotationsAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IAnnotation>> | The list of IAnnotations for the entire document. |
GetAnnotationsAsync(Int32)
Gets IAnnotations for a specific page index.
Declaration
public IAsyncOperation<IList<IAnnotation>> GetAnnotationsAsync(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IAnnotation>> | The list of IAnnotations on the specified page. |
GetBookmarksAsync()
Get the Bookmarks for this document.
Declaration
public IAsyncOperation<IList<Bookmark>> GetBookmarksAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<Bookmark>> | A collection of Bookmark. |
GetDocumentOutlineAsync()
Gets the outline for the document.
Declaration
public IAsyncOperation<IList<OutlineElement>> GetDocumentOutlineAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<OutlineElement>> | A List of OutlineElements in a tree like structure. |
GetDocumentOutlineForPageAsync(Int32)
Gets the outline elements for a specified page index in the document.
Declaration
public IAsyncOperation<IList<OutlineElement>> GetDocumentOutlineForPageAsync(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<OutlineElement>> | A List of OutlineElements in a tree like structure. |
GetFormFieldsAsync()
Returns a list of all form fields.
Declaration
public IAsyncOperation<IList<IFormField>> GetFormFieldsAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Collections.Generic.IList<IFormField>> | A list of IFormField. |
GetMarkupAnnotationTextAsync(IAnnotation)
Extracts the text behind a markup annotation. This can be useful to get the highlighted text. Warning: This is only an approximation. Highlighted text might not always 100% represent the text, as we just look behind the absolute coordinates to see what text is beneath. PDF highlight annotations are not markers in the content itself.
Declaration
public IAsyncOperation<string> GetMarkupAnnotationTextAsync(IAnnotation annotation)
Parameters
Type | Name | Description |
---|---|---|
IAnnotation | annotation | The text markup annotation from behind which you want to extract the text. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.String> | The text behind the annotation. |
GetPageBoxAsync(Int32, BoxType)
Gets media or crop box for the specified page
Declaration
public IAsyncOperation<Rect?> GetPageBoxAsync(int pageIndex, BoxType boxType)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The index of the page |
BoxType | boxType | The box type you want to receive |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Nullable<Windows.Foundation.Rect>> | The box of the page. Box may not be populated therefore the type is nullable. |
GetPageLabelAsync(Int32, Boolean)
Gets a page label.
Declaration
public IAsyncOperation<string> GetPageLabelAsync(int pageIndex, bool substituteWithPlainLabel)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | Index of the page to get the page label for. |
System.Boolean | substituteWithPlainLabel | If set to |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.String> | The page label. |
GetPageRotationAsync(Int32)
Gets the rotation for the specified page
Declaration
public IAsyncOperation<int> GetPageRotationAsync(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The index of the page |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Int32> | The rotation of the page |
GetPageSizeAsync(Int32)
Gets the PDF dimensions for the specified page
Declaration
public IAsyncOperation<Size> GetPageSizeAsync(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The index of the page |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Windows.Foundation.Size> | The size of the page |
GetSignaturesInfoAsync()
Gets the digital signatures validation information for all the signatures present in the current document. See SignaturesInfo
Declaration
public IAsyncOperation<SignaturesInfo> GetSignaturesInfoAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<SignaturesInfo> | The SignaturesInfo for the current document. |
GetTextParserAsync(Int32)
Get the TextParser for the specified page. A TextParser is useful for getting things like the page text and glyphs.
Declaration
public IAsyncOperation<TextParser> GetTextParserAsync(int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | pageIndex | The page to get the TextParser for. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<TextParser> | A TextParser. |
GetTitleAsync()
Gets the document's title fom metadata if one is set. If a title is not set in the PDF the string "Untitled" is returned.
Declaration
public IAsyncOperation<string> GetTitleAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.String> | The document title. |
GetTotalPageCountAsync()
Gets the total page count for the currently opened document.
Declaration
public IAsyncOperation<int> GetTotalPageCountAsync()
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<System.Int32> | Page count |
ImportInstantJsonAsync(JsonObject)
Load a document state from Instant Json. Will throw if the json is malformed or the PDF ID does not match the document which is currently open.
Declaration
public IAsyncAction ImportInstantJsonAsync(JsonObject json)
Parameters
Type | Name | Description |
---|---|---|
Windows.Data.Json.JsonObject | json | A string holding the Instant Json. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ImportXfdfAsync(IDataProvider)
Import XFDF information from a string and display in the current document.
Declaration
public IAsyncAction ImportXfdfAsync(IDataProvider xfdf)
Parameters
Type | Name | Description |
---|---|---|
IDataProvider | xfdf | A IDataProvider holding the xfdf data. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
ImportXfdfFileAsync(StorageFile)
Import XFDF information from a file and display in the current document.
Declaration
public IAsyncAction ImportXfdfFileAsync(StorageFile xfdfFile)
Parameters
Type | Name | Description |
---|---|---|
Windows.Storage.StorageFile | xfdfFile | The xfdf file to read from. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
OpenDocumentAsync(DocumentSource)
Opens a document from the DocumentSource. Throws if there was a problem opening.
Declaration
public static IAsyncOperation<Document> OpenDocumentAsync(DocumentSource source)
Parameters
Type | Name | Description |
---|---|---|
DocumentSource | source | The source of the document. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Document> | The opened document. |
PreviewRedactionsAsync(Boolean)
Controls whether to show the outlined state or redacted state for redaction annotations.
When set to false (default), the outline is shown. When set to true, the redaction state is shown, previewing their effect.
See ApplyRedactionsAsync() for properly applying the redactions.
This method is relevant only for usage with a PdfView.
Declaration
public IAsyncAction PreviewRedactionsAsync(bool showPreview)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | showPreview | Whether or not the PdfView should display the annotations in preview mode. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
SignAndSaveAsync(HashAlgorithm, String, String, SignatureMetadata)
Signs the document and saves it.
Declaration
public IAsyncAction SignAndSaveAsync(HashAlgorithm hashAlgorithm, string certificate, string privateKey, SignatureMetadata signatureMetadata)
Parameters
Type | Name | Description |
---|---|---|
HashAlgorithm | hashAlgorithm | The HashAlgorithm used to create the document digest. |
System.String | certificate | The certificate used to sign the document in PEM format. Optional if using two step signing. TwoStepSignatureSigning. |
System.String | privateKey | The private key used to sign the document in PEM format. Optional if using two step signing. TwoStepSignatureSigning. |
SignatureMetadata | signatureMetadata | Contains information and metadata to be used for a digital signature. SignatureMetadata |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncAction |
UpdateAnnotationAsync(IAnnotation)
Updates an existing IAnnotation.
Declaration
public IAsyncOperation<IAnnotation> UpdateAnnotationAsync(IAnnotation annotation)
Parameters
Type | Name | Description |
---|---|---|
IAnnotation | annotation | An IAnnotation to be updated. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<IAnnotation> | The updated IAnnotation. |
UpdateBookmarkAsync(Bookmark)
Update Bookmark to the document.
Declaration
public IAsyncOperation<Bookmark> UpdateBookmarkAsync(Bookmark bookmark)
Parameters
Type | Name | Description |
---|---|---|
Bookmark | bookmark | The bookmark to be updated. |
Returns
Type | Description |
---|---|
Windows.Foundation.IAsyncOperation<Bookmark> | The updated bookmark. |
Events
AnnotationsCreated
Occurs whenever annotations are created (either via the public Document or via the UI).
Declaration
public event TypedEventHandler<Document, IList<IAnnotation>> AnnotationsCreated
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<IAnnotation>> |
AnnotationsDeleted
Occurs whenever annotations are deleted (either via the public Document or via the UI).
Declaration
public event TypedEventHandler<Document, IList<IAnnotation>> AnnotationsDeleted
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<IAnnotation>> |
AnnotationsUpdated
Occurs whenever annotations are updated (either via the public Document or via the UI).
Declaration
public event TypedEventHandler<Document, IList<IAnnotation>> AnnotationsUpdated
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<IAnnotation>> |
BookmarksCreated
Invoked when bookmarks are created.
Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksCreated
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<Bookmark>> |
BookmarksDeleted
Invoked when bookmarks are deleted. A list of the bookmark ids that were deleted is passed.
Declaration
public event TypedEventHandler<Document, IList<string>> BookmarksDeleted
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<System.String>> |
BookmarksUpdated
Invoked when bookmarks are updated.
Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksUpdated
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<Bookmark>> |
ModifiedAt
Occurs whenever the document has been modified.
Declaration
public event TypedEventHandler<Document, DateTimeOffset> ModifiedAt
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Document, System.DateTimeOffset> |
TwoStepSignatureSigning
This event is invoked when a document has been prepared for digitally signing by calling SignAndSaveAsync(HashAlgorithm, String, String, SignatureMetadata). It receives the current document hash and file contents to be signed as arguments, and must return a PKCS7 container to sign the document with in the deferral.
The provided file contents can be used as input for a cryptographic library or service of your choice to be signed (hashed and encrypted in a PKCS7 container). The file contents hash is also provided so it can be used it to verify the validity of the contents.
Declaration
public event TypedEventHandler<Deferral, SigningData> TwoStepSignatureSigning
Event Type
Type | Description |
---|---|
Windows.Foundation.TypedEventHandler<Windows.Foundation.Deferral, SigningData> |