Class Document

This class represents a PDF Document.

Inheritance
System.Object
Document
Namespace: PSPDFKit.Pdf
Assembly: PSPDFKit.dll
Syntax
public sealed class Document

Properties

DocumentSource

Declaration
public DocumentSource DocumentSource { get; }
Property Value
Type Description
DocumentSource

Methods

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 currently displayed pages.

Returns
Type Description
Windows.Foundation.IAsyncOperation<IAnnotation>

The newly created IAnnotation.

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. Note that Id is ignored and the returned bookmark will have a new Id.

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.

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 PDF 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 PDF will be saved

Returns
Type Description
Windows.Foundation.IAsyncAction

ExportAsync(StorageFile, DocumentExportOptions)

Export the PDF 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 PDF 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 PDF will be written to.

DocumentExportOptions options

Advanced options for saving a processed document.

Returns
Type Description
Windows.Foundation.IAsyncAction

ExportToDataWriterAsync(DataWriter, DocumentExportOptions)

Export the PDF 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 PDF 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.

GetDocumentOutline()

Gets the outline for the document.

Declaration
public IAsyncOperation<IList<OutlineElement>> GetDocumentOutline()
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 poulated 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 true then this always returns a valid string. If the document contains no page labels and this parameter is set to false, this will return an empty response.

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

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 currently opened PDF's total page count.

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 pdfid 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.

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.

Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksDeleted
Event Type
Type Description
Windows.Foundation.TypedEventHandler<Document, System.Collections.Generic.IList<Bookmark>>

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>>