Class Document

This class represents a PDF Document.

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

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

The buffer containing the attachment binary.

System.String contentType

The content type of the attachment. E.g. "image/png"

Returns
Type Description
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
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
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
IAsyncAction

ExportAsync(StorageFile)

Export the PDF to a

Declaration
public IAsyncAction ExportAsync(StorageFile file)
Parameters
Type Name Description
StorageFile file

The file into which the current state of the PDF will be saved

Returns
Type Description
IAsyncAction

ExportAsync(StorageFile, DocumentExportOptions)

Declaration
public IAsyncAction ExportAsync(StorageFile file, DocumentExportOptions options)
Parameters
Type Name Description
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
IAsyncAction

ExportFlattenedAsync(StorageFile)

Export the PDF with annotations flattened to a

Declaration
public IAsyncAction ExportFlattenedAsync(StorageFile file)
Parameters
Type Name Description
StorageFile file

The file into which the current state of the PDF will be flattened and saved

Returns
Type Description
IAsyncAction

ExportFlattenedToDataWriterAsync(DataWriter)

Export the PDF with annotations flattened to a . Known issue: Caller must reopen document after exporting with this method.

Declaration
public IAsyncAction ExportFlattenedToDataWriterAsync(DataWriter dataWriter)
Parameters
Type Name Description
DataWriter dataWriter

The into which the current state of the PDF will be flattened and written.

Returns
Type Description
IAsyncAction

ExportInstantJsonAsync()

Return a representation of the current document state in Instant Json.

Declaration
public IAsyncOperation<JsonObject> ExportInstantJsonAsync()
Returns
Type Description
IAsyncOperation<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
IAsyncAction

ExportToDataWriterAsync(DataWriter, DocumentExportOptions)

Export the PDF to a . Known issue: Caller must reopen document after exporting with this method.

Declaration
public IAsyncAction ExportToDataWriterAsync(DataWriter dataWriter, DocumentExportOptions options)
Parameters
Type Name Description
DataWriter dataWriter

The into which the current state of the PDF will be written.

DocumentExportOptions options

Advanced options for saving a processed document.

Returns
Type Description
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
IAsyncAction

ExportXfdfToDataWriterAsync(DataWriter)

Export current annotations to XFDF to a .

Declaration
public IAsyncAction ExportXfdfToDataWriterAsync(DataWriter dataWriter)
Parameters
Type Name Description
DataWriter dataWriter
Returns
Type Description
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
IAsyncOperation<Attachment>

An Attachment

GetAnnotationsAsync()

Gets IAnnotations for the whole document.

Declaration
public IAsyncOperation<IList<IAnnotation>> GetAnnotationsAsync()
Returns
Type Description
IAsyncOperation<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
IAsyncOperation<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
IAsyncOperation<IList<Bookmark>>

A collection of Bookmark.

GetDocumentOutline()

Gets the outline for the document.

Declaration
public IAsyncOperation<IList<OutlineElement>> GetDocumentOutline()
Returns
Type Description
IAsyncOperation<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
IAsyncOperation<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
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
IAsyncOperation<System.Nullable<Rect>>

The box of the page. Box may not be poulated therefore the type is nullable.

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

The size of the page

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
IAsyncOperation<System.String>

The document title.

GetTotalPageCountAsync()

Gets the currently opened PDF's total page count.

Declaration
public IAsyncOperation<int> GetTotalPageCountAsync()
Returns
Type Description
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
JsonObject json

A string holding the Instant Json.

Returns
Type Description
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
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
StorageFile xfdfFile

The xfdf file to read from.

Returns
Type Description
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
IAsyncOperation<Document>

The opened document.

TextForPageIndexAsync(Int32)

Gets the text for the page at the specified index

Declaration
public IAsyncOperation<IList<TextBlock>> TextForPageIndexAsync(int pageIndex)
Parameters
Type Name Description
System.Int32 pageIndex

The page index

Returns
Type Description
IAsyncOperation<IList<TextBlock>>

A List of TextBlocks.

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
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
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
TypedEventHandler<Document, 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
TypedEventHandler<Document, 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
TypedEventHandler<Document, IList<IAnnotation>>

BookmarksCreated

Invoked when bookmarks are created.

Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksCreated
Event Type
Type Description
TypedEventHandler<Document, IList<Bookmark>>

BookmarksDeleted

Invoked when bookmarks are deleted.

Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksDeleted
Event Type
Type Description
TypedEventHandler<Document, IList<Bookmark>>

BookmarksUpdated

Invoked when bookmarks are updated.

Declaration
public event TypedEventHandler<Document, IList<Bookmark>> BookmarksUpdated
Event Type
Type Description
TypedEventHandler<Document, IList<Bookmark>>