PdfDocument

interface PdfDocument

A PDF document. To create an instance use PdfDocumentLoader.openDocument or related static methods on the PdfDocumentLoader class.

Inheritors

Types

Link copied to clipboard
object Companion

Page-rotation constants (degrees, clockwise) returned by getPageRotation / getRotationOffset.

Link copied to clipboard
annotation class PageRotation

Indicates that the returned value is a page rotation.

Properties

Link copied to clipboard

AnnotationProvider object which handles annotations contained in this document.

Link copied to clipboard

BookmarkProvider object which handles bookmarks contained in this document.

Link copied to clipboard
abstract val changeId: ByteArray

Document Identifier used for AiAssistant, represents if document is updated.

Link copied to clipboard

PdfDocumentCheckpointer object which handles the checkpoint for the document. May be null if checkpoint is not supported.

Link copied to clipboard

A default set of document save options which have the same permissions, password and PDF version set as this document.

Link copied to clipboard
abstract val documentId: ByteArray

A permanent document identifier (inferred from document provider if possible). According to the PDF spec, this is based on the contents of the file at the time it was originally created, but in practice we might as well assume it to be random data. The value depends on the first document provider and may change after change to the document providers array.

Link copied to clipboard
abstract val documentIdString: String

A string representation of a document identifier.

Link copied to clipboard

Information about digital signatures in this document. This call may block for a while and should not be called from the main thread.

Link copied to clipboard

The original DocumentSource of this PdfDocument. If the document is a compound one (i.e. it contains multiple files) this returns the first entry of the list returned by documentSources.

Link copied to clipboard

List of DocumentSources from which this document is loaded. A source can be either a file URI or a com.pspdfkit.document.providers.DataProvider. Only compound documents will have multiple sources. For a non-compound document the list will contain a single entry.

Link copied to clipboard

EmbeddedFilesProvider object which handles embedded files contained in this document.

Link copied to clipboard

FormProvider object which handles forms contained in this document.

Link copied to clipboard

Whether or not automatic link generation is enabled. This property dictates if the document's text should be parsed and any clickable links automatically generated with its corresponding com.pspdfkit.annotations.LinkAnnotation.

Link copied to clipboard
abstract val isEncrypted: Boolean

Indicates if the PDF document is encrypted (= password protected).

Link copied to clipboard

Whether or not watermark filtering is enabled. setWatermarkTextFilteringEnabled dictates whether watermark text is filtered from text retrieval methods.

Link copied to clipboard

Whether the document data sources are read/write (come from a supported source) and whether saving is enabled. A compound document is writable when all of its sources are, saving writes each of them back to the file or data provider it was loaded from.

Link copied to clipboard

JavaScriptProvider object which handles JavaScript execution for this document.

Link copied to clipboard

List of top-level (outline / table-of-contents) bookmarks. Bookmarks are organized in a tree-like structure and can have children. Note that this may take a while and should not be called on the main thread. If you want a quick check for whether document has outline, use hasOutline.

Link copied to clipboard
abstract var pageBinding: PageBinding

The current document's PageBinding. This sets how the document is displayed, either left to right (page indexed 0 will be to the left), or right to left (page indexed 0 will be on the right). It is stored in the document metadata and persisted when reopening the document.

Link copied to clipboard
abstract val pageCount: Int

Number of pages in this document.

Link copied to clipboard

Metadata (title, author, creation date, ...) stored in the PDF document dictionary.

Link copied to clipboard

Auxiliary projection class for mapping coordinate space between raw and normalized PDF.

Link copied to clipboard
abstract val pdfVersion: PdfVersion

Current PDF version of the document, a value from the PdfVersion enum.

Link copied to clipboard
abstract val permanentId: ByteArray

Unique Document Identifier used for AiAssistant.

Link copied to clipboard

Set of currently applied permission flags on this document.

Link copied to clipboard

The secondary unit value from the document, or null if none is set.

Link copied to clipboard
abstract val title: String?

A document title, resolved in this order:

Link copied to clipboard
abstract val uid: String

This is the unique identifier for this document. It will be created automatically based on the content sources.

Link copied to clipboard

Document metadata stored in the XMP metadata entries included in the PDF file.

Functions

Link copied to clipboard
abstract suspend fun addLongTermValidation(signatureFormElement: SignatureFormElement, certificates: List<@JvmSuppressWildcards X509Certificate>)

This adds long term validation to an existing signature form element that has already been signed or refreshes that information if the signature is already LTV enabled.

Link copied to clipboard
fun PdfDocument.createTextBlock(@IntRange(from = 0) pageIndex: Int, range: Range): TextBlock

Creates a TextBlock from the given page.

Link copied to clipboard
abstract fun getCharIndexAt(@IntRange(from = 0) pageIndex: Int, x: Float, y: Float): Int

Return the index of the closest character whose rect intersects the given x and y coordinates.

Link copied to clipboard

Information about digital signatures in this document. This will be executed on a background dispatcher.

Link copied to clipboard

Returns the hash of a particular byte range of the document. This method works only on the first source of a compound document, use getHashForDocumentRange with a source index if you want to digest other sources.

abstract fun getHashForDocumentRange(providerIndex: Int, range: List<@JvmSuppressWildcards Long>, hashAlgorithm: HashAlgorithm): ByteArray

Returns the hash of a particular byte range of the document.

Link copied to clipboard

List of top-level (outline / table-of-contents) bookmarks, asynchronously. Bookmarks are organized in a tree-like structure and can have children.

Link copied to clipboard
abstract fun getPageBox(@IntRange(from = 0) pageIndex: Int, box: PdfBox): RectF

Returns rectangle describing one of the PDF page boxes. If the page box dimension is not present in the PDF document, it's considered to be as large as the actual page size from getPageSize.

Link copied to clipboard
abstract fun getPageIndexForPageLabel(pageLabel: String, partialMatching: Boolean): Int?

Gets the page index for the given page label.

Link copied to clipboard
abstract fun getPageLabel(@IntRange(from = 0) pageIndex: Int, substituteWithPlainLabel: Boolean): String?

Gets the page label.

Link copied to clipboard
abstract fun getPageRotation(@IntRange(from = 0) pageIndex: Int): Int

Returns a page rotation in degrees.

Link copied to clipboard
abstract fun getPageSize(@IntRange(from = 0) pageIndex: Int): Size

Returns a page size in PDF points.

Link copied to clipboard
abstract fun getPageText(@IntRange(from = 0) pageIndex: Int): String

Returns text content of the document page.

abstract fun getPageText(@IntRange(from = 0) pageIndex: Int, rectF: RectF): String

Returns text content inside given page rectangle.

abstract fun getPageText(@IntRange(from = 0) pageIndex: Int, start: Int, length: Int): String

Returns text content between two character indexes. Use getPageTextLength to determine the number of characters on page.

Link copied to clipboard
abstract fun getPageTextLength(@IntRange(from = 0) pageIndex: Int): Int

Gets number of characters in text on the page.

Link copied to clipboard
abstract fun getPageTextRects(@IntRange(from = 0) pageIndex: Int, startIndex: Int, length: Int): List<@JvmSuppressWildcards RectF>
abstract fun getPageTextRects(@IntRange(from = 0) pageIndex: Int, startIndex: Int, length: Int, markupPadding: Boolean): List<@JvmSuppressWildcards RectF>

Returns the rects of the range of characters on a page.

Link copied to clipboard
abstract fun getRotationOffset(@IntRange(from = 0) pageIndex: Int): Int

Returns the rotation offset applied to this page in degrees.

Link copied to clipboard

Returns page text for a list of text blocks. The text is created by sequentially concatenating text blocks with a single space used as a separator.

Link copied to clipboard
abstract fun hasEmbeddedFile(): Boolean

Returns whether the document has any embedded files.

Link copied to clipboard
abstract fun hasOutline(): Boolean

Checks whether this document has outline / table of contents.

Link copied to clipboard
abstract fun hasPermission(permission: DocumentPermissions): Boolean

Test document permission flags.

Link copied to clipboard
abstract fun initPageCache()

Pre-fetches rotations, sizes and labels for all pages on a background thread. Caching will only be performed once (for the first caller). If you need a callback to be notified of when caching is done, use the async variant initPageCacheAsync instead.

Link copied to clipboard
abstract suspend fun initPageCacheAsync()

Pre-fetches rotations, sizes and labels for all pages on a background thread. Caching will only be performed once (for the first caller). All subsequent callers suspend until the cache is built, then return.

Link copied to clipboard
abstract fun invalidateCache()

Invalidates the rendered cache of all the pages for this document. Use this method if the document is not updated after a change, or changed externally, and needs to be re-rendered.

Link copied to clipboard
abstract fun invalidateCacheForPage(@IntRange(from = 0) pageIndex: Int)

Invalidates the rendered cache of the given pageIndex for this document. Use this method if a single page of the document is not updated after a change, or changed externally, and needs to be re-rendered.

Link copied to clipboard
abstract fun renderPageToBitmap(context: Context, pageIndex: Int, width: Int, height: Int): Bitmap
abstract fun renderPageToBitmap(context: Context, pageIndex: Int, width: Int, height: Int, configuration: PageRenderConfiguration): Bitmap

Renders page to a bitmap.

Link copied to clipboard
abstract suspend fun renderPageToBitmapAsync(context: Context, pageIndex: Int, width: Int, height: Int): Bitmap
abstract suspend fun renderPageToBitmapAsync(context: Context, @IntRange(from = 0) pageIndex: Int, width: Int, height: Int, configuration: PageRenderConfiguration): Bitmap

Renders page to a bitmap.

Link copied to clipboard
abstract fun save(path: String)
abstract fun save(path: String, saveOptions: DocumentSaveOptions)

Saves the document to an external file even if it hasn't been changed. Note that this may take a while and should not be called on the main thread. This will not clear the wasModified flag on this document instance, and will not replace the source of this document either (i.e. subsequent calls to saveIfModified will still save the document back to the original file).

Link copied to clipboard
abstract suspend fun saveAsync(path: String)
abstract suspend fun saveAsync(path: String, saveOptions: DocumentSaveOptions)

Saves the document to an external file even if it hasn't been changed. This will not clear the wasModified flag on this document instance, and will not replace the source of this document either (i.e. subsequent calls to saveIfModified will still save the document back to the original file).

Link copied to clipboard
abstract fun saveIfModified(): Boolean
abstract fun saveIfModified(saveOptions: DocumentSaveOptions): Boolean

Saves the document to original location if it has been changed. If there were no changes to the document, the document file will not be modified. Note that this may take a while and should not be called on the main thread.

abstract fun saveIfModified(path: String): Boolean
abstract fun saveIfModified(path: String, saveOptions: DocumentSaveOptions): Boolean

Saves the document to passed location if it has been changed. If there were no changes to the document, the output file won't be modified. Note that this may take a while and should not be called on the main thread. This will not clear the wasModified flag on this document instance, and will not replace the source of this document either (i.e. subsequent calls to saveIfModified will still save the document back to the original file).

Link copied to clipboard
abstract suspend fun saveIfModifiedAsync(): Boolean
abstract suspend fun saveIfModifiedAsync(saveOptions: DocumentSaveOptions): Boolean

Saves the document back to original location if it has been changed. If there were no changes to the document, the document file will not be modified.

abstract suspend fun saveIfModifiedAsync(path: String): Boolean
abstract suspend fun saveIfModifiedAsync(path: String, saveOptions: DocumentSaveOptions): Boolean

Saves the document to an external file if it has been changed. This will not clear the wasModified flag on this document instance, and will not replace the source of this document either (i.e. subsequent calls to saveIfModified will still save the document back to the original file).

Link copied to clipboard
abstract fun setRotationOffset(pageRotation: Int, @IntRange(from = 0) pageIndex: Int)

Applies a temporary rotation to the specified page of this document. This will change the size reported by the document to match the new rotation. The document will not be modified by this. If you plan on applying a rotation to multiple pages use setRotationOffsets.

Link copied to clipboard
abstract fun setRotationOffsets(pageRotations: SparseIntArray)

Applies a temporary rotation to the specified pages of this document. This will change the size reported by the document to match the new rotation. The document will not be modified by this. If you plan on applying a rotation to a single page use setRotationOffset.

Link copied to clipboard
abstract fun setSecondaryMeasurementUnit(secondaryMeasurementUnit: SecondaryMeasurementUnit)

Sets the secondary unit value on the document.

Link copied to clipboard

Enables or disables filtering of watermark text in text retrieval methods. Note that this will not prevent the rendering of the watermark on the page.

Link copied to clipboard
abstract fun wasModified(): Boolean

Returns true if this document was modified and should be saved to retain changes.