com.pspdfkit.document.PdfDocument |
![]() |
A PDF document. To create an instance use openDocument(Context, Uri)
or related static methods on the PdfDocumentLoader
class.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
@interface | PdfDocument.PageRotation | Indicates that the returned value is a page rotation. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | NO_ROTATION | Rotation value returned for pages that aren't rotated. | |||||||||
int | ROTATION_180 | Rotation value returned for pages that are rotated 180°. | |||||||||
int | ROTATION_270 | Rotation value returned for pages that are rotated 270°. | |||||||||
int | ROTATION_90 | Rotation value returned for pages that are rotated 90°. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract AnnotationProvider |
getAnnotationProvider()
Returns
AnnotationProvider object which handles annotations contained in this document. | ||||||||||
abstract BookmarkProvider |
getBookmarkProvider()
Returns
BookmarkProvider object which handles bookmarks contained in this document. | ||||||||||
abstract int |
getCharIndexAt(int pageIndex, float x, float y)
Return the index of the closest character whose rect intersects the given
x and y coordinates. | ||||||||||
abstract PdfDocumentCheckpointer |
getCheckpointer()
Returns
PdfDocumentCheckpointer object which handles the checkpoint for the document. | ||||||||||
abstract DocumentSaveOptions |
getDefaultDocumentSaveOptions()
Returns a default set of document save options which have same permissions,
password and PDF version set as this document.
| ||||||||||
abstract DocumentSignatureInfo |
getDocumentSignatureInfo()
Returns information about digital signatures in this document.
| ||||||||||
abstract Single<DocumentSignatureInfo> |
getDocumentSignatureInfoAsync()
Returns information about digital signatures in this document.
| ||||||||||
abstract DocumentSource |
getDocumentSource()
Returns source of this document.
| ||||||||||
abstract List<DocumentSource> |
getDocumentSources()
Returns list of
DocumentSource s from which this document is loaded. | ||||||||||
abstract EmbeddedFilesProvider |
getEmbeddedFilesProvider()
Returns
EmbeddedFilesProvider object which handles embedded files contained in this document. | ||||||||||
abstract FormProvider |
getFormProvider()
Returns
FormProvider object which handles forms contained in this document. | ||||||||||
abstract byte[] |
getHashForDocumentRange(int sourceIndex, List<Long> range, HashAlgorithm hashAlgorithm)
Returns the hash of a particular byte range of the document.
| ||||||||||
abstract byte[] |
getHashForDocumentRange(List<Long> range, HashAlgorithm hashAlgorithm)
Returns the hash of a particular byte range of the document.
| ||||||||||
abstract JavaScriptProvider |
getJavaScriptProvider()
Returns
JavaScriptProvider object which handles JavaScript execution for this document. | ||||||||||
abstract List<OutlineElement> |
getOutline()
Returns list of top-level (outline / table-of-contents) bookmarks.
| ||||||||||
abstract Single<List<OutlineElement>> |
getOutlineAsync()
Returns list of top-level (outline / table-of-contents) bookmarks, asynchronously.
| ||||||||||
abstract PageBinding | getPageBinding() | ||||||||||
abstract RectF |
getPageBox(int pageIndex, PdfBox box)
Returns rectangle describing one of the PDF page boxes.
| ||||||||||
abstract int |
getPageCount()
Returns number of pages in this document.
| ||||||||||
abstract Integer |
getPageIndexForPageLabel(String pageLabel, boolean partialMatching)
Gets the page index for the given page label.
| ||||||||||
abstract String |
getPageLabel(int pageIndex, boolean substituteWithPlainLabel)
Gets the page label.
| ||||||||||
abstract int |
getPageRotation(int pageIndex)
Returns a page rotation in degrees.
| ||||||||||
abstract Size |
getPageSize(int pageIndex)
Returns a page size in PDF points.
| ||||||||||
abstract String |
getPageText(int pageIndex, int start, int length)
Returns text content between two character indexes.
| ||||||||||
abstract String |
getPageText(int pageIndex)
Returns text content of the document page.
| ||||||||||
abstract String |
getPageText(int pageIndex, RectF rectF)
Returns text content inside given page rectangle.
| ||||||||||
abstract int |
getPageTextLength(int pageIndex)
Gets number of characters in text on the page.
| ||||||||||
abstract List<RectF> |
getPageTextRects(int pageIndex, int startIndex, int length)
Returns the rects of the range of characters on a page.
| ||||||||||
abstract List<RectF> |
getPageTextRects(int pageIndex, int startIndex, int length, boolean markupPadding)
Returns the rects of the range of characters on a page.
| ||||||||||
abstract DocumentPdfMetadata |
getPdfMetadata()
Returns metadata (title, author, creation date, ...) of this document, stored in the PDF
document dictionary.
| ||||||||||
abstract PdfProjection |
getPdfProjection()
Returns auxiliary projection class for mapping coordinate space between raw and normalized Pdf.
| ||||||||||
abstract PdfVersion |
getPdfVersion()
Returns current PDF version of the document.
| ||||||||||
abstract EnumSet<DocumentPermissions> |
getPermissions()
Returns set of currently applied permission flags on this document.
| ||||||||||
abstract int |
getRotationOffset(int pageIndex)
Returns the rotation offset applied to this page in degrees.
| ||||||||||
abstract String |
getTitle()
Returns a document title.
| ||||||||||
abstract String |
getUid()
This is the unique identifier for this document.
| ||||||||||
abstract DocumentXmpMetadata |
getXmpMetadata()
Returns document metadata stored in the XMP metadata entries included in the PDF file.
| ||||||||||
abstract boolean |
hasOutline()
Checks whether this document has outline / table of contents
| ||||||||||
abstract boolean |
hasPermission(DocumentPermissions permission)
Test document permission flags.
| ||||||||||
abstract void |
initPageCache()
Pre-fetches rotations, sizes and labels for all pages on a background thread.
| ||||||||||
abstract Completable |
initPageCacheAsync()
Pre-fetches rotations, sizes and labels for all pages on a background thread.
| ||||||||||
abstract void |
invalidateCache()
Invalidates render cache for images of the given
document . | ||||||||||
abstract void |
invalidateCacheForPage(int pageIndex)
Invalidates render cache for images of the given
pageIndex of the document . | ||||||||||
abstract boolean | isAutomaticLinkGenerationEnabled() | ||||||||||
abstract boolean |
isValidForEditing()
Returns
true if the document is editable (is not compounded and comes from a supported source),
false otherwise. | ||||||||||
abstract boolean | isWatermarkFilteringEnabled() | ||||||||||
abstract Bitmap |
renderPageToBitmap(Context context, int pageIndex, int width, int height)
Renders page to a bitmap.
| ||||||||||
abstract Bitmap |
renderPageToBitmap(Context context, int pageIndex, int width, int height, PageRenderConfiguration configuration)
Renders page to a bitmap.
| ||||||||||
abstract Single<Bitmap> |
renderPageToBitmapAsync(Context context, int pageIndex, int width, int height, PageRenderConfiguration configuration)
Renders page to a bitmap.
| ||||||||||
abstract Single<Bitmap> |
renderPageToBitmapAsync(Context context, int pageIndex, int width, int height)
Renders page to a bitmap.
| ||||||||||
abstract void |
save(String path, DocumentSaveOptions saveOptions)
Saves the document even if it hasn't been changed.
| ||||||||||
abstract void |
save(String path)
Saves the document even if it hasn't been changed.
| ||||||||||
abstract Completable |
saveAsync(String path)
Saves the document even if it hasn't been changed.
| ||||||||||
abstract Completable |
saveAsync(String path, DocumentSaveOptions saveOptions)
Saves the document even if it hasn't been changed.
| ||||||||||
abstract boolean |
saveIfModified(DocumentSaveOptions saveOptions)
Saves the document to original location if it has been changed.
| ||||||||||
abstract boolean |
saveIfModified()
Saves the document to original location if it has been changed.
| ||||||||||
abstract boolean |
saveIfModified(String path)
Saves the document to passed location if it has been changed.
| ||||||||||
abstract boolean |
saveIfModified(String path, DocumentSaveOptions saveOptions)
Saves the document to passed location if it has been changed.
| ||||||||||
abstract Single<Boolean> |
saveIfModifiedAsync()
Saves the document back to original location if it has been changed.
| ||||||||||
abstract Single<Boolean> |
saveIfModifiedAsync(DocumentSaveOptions saveOptions)
Saves the document back to original location if it has been changed.
| ||||||||||
abstract Single<Boolean> |
saveIfModifiedAsync(String path, DocumentSaveOptions saveOptions)
Saves the document to passed location if it has been changed.
| ||||||||||
abstract Single<Boolean> |
saveIfModifiedAsync(String path)
Saves the document to passed location if it has been changed.
| ||||||||||
abstract void |
setAutomaticLinkGenerationEnabled(boolean enabled)
Enables or disables automatic link generation.
| ||||||||||
abstract void |
setPageBinding(PageBinding pageBinding)
Sets the
PageBinding controlling in which direction pages of documents are laid out. | ||||||||||
abstract void |
setRotationOffset(int pageRotation, int pageIndex)
Applies a temporary rotation to the specified page of this document.
| ||||||||||
abstract void |
setRotationOffsets(SparseIntArray pageRotations)
Applies a temporary rotation to the specified pages of this document.
| ||||||||||
abstract void |
setWatermarkTextFilteringEnabled(boolean enabled)
Enables or disables filtering of watermark text in text retrieval methods.
| ||||||||||
abstract boolean |
wasModified()
Returns
true if this document was modified and should be saved to retain changes. |
Rotation value returned for pages that aren't rotated.
Rotation value returned for pages that are rotated 180°.
Rotation value returned for pages that are rotated 270°.
Rotation value returned for pages that are rotated 90°.
Returns AnnotationProvider
object which handles annotations contained in this document.
Returns BookmarkProvider
object which handles bookmarks contained in this document.
Return the index of the closest character whose rect intersects the given
x
and y
coordinates.
pageIndex | Page number of the page, zero indexed. |
---|---|
x | X coordinate in PDF point units (usually 1/72 of an inch). |
y | Y coordinate in PDF point units (usually 1/72 of an inch). |
-1
if no character was found at the given coordinates.
Returns PdfDocumentCheckpointer
object which handles the checkpoint for the document.
May return null
if checkpoint is not supported.
PdfDocumentCheckpointer
object which handles the checkpoint for the document.
Returns a default set of document save options which have same permissions, password and PDF version set as this document.
Returns information about digital signatures in this document. This call may block for a while and should not be called from the main thread.
DocumentSignatureInfo
describing digital signatures in this document.
Returns information about digital signatures in this document. This will be executed on a background scheduler.
Single
containing the DocumentSignatureInfo
describing digital
signatures in this document.
Returns source of this document.
DocumentSource
of this PdfDocument
. If the document is a compound one (i.e. it contains multiple files) this method
returns the first entry of the array returned by getDocumentSources()
.
Returns list of DocumentSource
s from which this document is loaded. A source can be either a file URI or a DataProvider
. Only compound documents will have multiple sources.
DocumentSource
s for this PdfDocument
. If the document is a compound one (i.e. is read from multiple sources) it will
have several sources, otherwise it the list will contain a single entry.
Returns EmbeddedFilesProvider
object which handles embedded files contained in this document.
Returns FormProvider
object which handles forms contained in this document.
Returns the hash of a particular byte range of the document.
sourceIndex | Index of document source that should be hashed (valid only for compound documents). |
---|---|
range | The byte range of the part of the document that will be hashed. A byte range is an array of
pairs (byte offset, length in bytes) that describe the (possibly discontiguous) region of
the document that should be hashed. For an already prepared PDF document with a digital
signature, you can get this information via getByteRange() on
signature info retrieved via getSignatureInfo() . |
hashAlgorithm | The hash algorithm that will be used to generate the hashed data. |
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(int, List, HashAlgorithm)
if you want to digest other
sources.
range | The byte range of the part of the document that will be hashed. A byte range is an array of
pairs (byte offset, length in bytes) that describe the (possibly discontiguous) region of
the document that should be hashed. For an already prepared PDF document with a digital
signature, you can get this information via getByteRange() on
signature info retrieved via getSignatureInfo() . |
---|---|
hashAlgorithm | The hash algorithm that will be used to generate the hashed data. |
Returns JavaScriptProvider
object which handles JavaScript execution for this document.
Returns 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()
.
Note: When this document is a compound document, calling this method will only ever return the outline of the first document source.
Returns list of top-level (outline / table-of-contents) bookmarks, asynchronously. Bookmarks are organized in a tree-like structure and can have children.
Note: When this document is a compound document, calling this method will only ever return the outline of the first document source.
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(int)
.
pageIndex | Page number of the page to render, zero indexed. |
---|---|
box | Box to retrieve for the page, from PdfBox . |
Returns number of pages in this document.
Gets the page index for the given page label.
pageLabel | The page label to search for. |
---|---|
partialMatching | If false, the exact string will be searched for. Otherwise we will return the best match. |
null
.
Gets the page label.
pageIndex | The index of the page. |
---|---|
substituteWithPlainLabel | If true, and no page label exists for the given page, returns a string with the page number. |
null
if not found.
Returns a page rotation in degrees.
pageIndex | Page index of the requested page, zero indexed. |
---|
Returns a page size in PDF points.
pageIndex | Page number of the page to render, zero indexed. |
---|
Size
page size object.
Returns text content between two character indexes. Use getPageTextLength(int)
to determine the number of characters on page.
pageIndex | 0-indexed page number. |
---|---|
start | Index of first character in the range. |
length | Length of the range. |
Returns text content of the document page.
pageIndex | 0-indexed page number. |
---|
Returns text content inside given page rectangle.
pageIndex | 0-indexed page number. |
---|---|
rectF | Page rectangle in the PDF coordinates. |
Gets number of characters in text on the page.
pageIndex | 0-indexed page number. |
---|
Returns the rects of the range of characters on a page.
pageIndex | Page number of the page, zero indexed. |
---|---|
startIndex | Index of the starting character. |
length | Number of characters in sequence. |
Returns the rects of the range of characters on a page.
pageIndex | Page number of the page, zero indexed. |
---|---|
startIndex | Index of the starting character. |
length | Number of characters in sequence. |
markupPadding | Take the font height into account in the rects to make better suited for being displayed around the text. |
Returns metadata (title, author, creation date, ...) of this document, stored in the PDF document dictionary.
Returns auxiliary projection class for mapping coordinate space between raw and normalized Pdf.
Returns current PDF version of the document.
PdfVersion
enum.
Returns set of currently applied permission flags on this document.
Returns the rotation offset applied to this page in degrees.
pageIndex | Page index of the requested page, zero indexed. |
---|
Returns a document title. Resolved in this order:
null
if no title is available.
This is the unique identifier for this document. It will be created automatically based on the content sources.
Returns document metadata stored in the XMP metadata entries included in the PDF file.
Checks whether this document has outline / table of contents
true
when the document has outline, false
if not.
Test document permission flags.
true
if permission flag is set on this document, false
otherwise.
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.
Pre-fetches rotations, sizes and labels for all pages on a background thread. Caching will only be performed once (for the first subscriber).
Invalidates render cache for images of the given document
.
Use this method if the document was changed externally and you need the rendered pages to be refreshed.
Invalidates render cache for images of the given pageIndex
of the document
.
Use this method if a single page of the document became and needs to be re-rendered.
pageIndex | 0-based index of the page to refresh. |
---|
true
if automatic link generation is enabled.Returns true
if the document is editable (is not compounded and comes from a supported source),
false
otherwise.
true
if the document supports editing, false
otherwise.
Renders page to a bitmap.
context | Application context. |
---|---|
pageIndex | Page number of the page to render, zero indexed. |
width | Bitmap width. |
height | Bitmap height. |
Renders page to a bitmap.
context | Application context. |
---|---|
pageIndex | Page number of the page to render, zero indexed. |
width | Bitmap width. |
height | Bitmap height. |
configuration | Advanced configuration options. |
Renders page to a bitmap.
context | Application context. |
---|---|
pageIndex | Page number of the page to render, zero indexed. |
width | Bitmap width. |
height | Bitmap height. |
configuration | Advanced configuration options. |
Renders page to a bitmap.
context | Application context. |
---|---|
pageIndex | Page number of the page to render, zero indexed. |
width | Bitmap width. |
height | Bitmap height. |
Saves the document even if it hasn't been changed. Note that this may take a while and should not be called on the main thread.
path | Absolute filepath to the output document file. |
---|---|
saveOptions | Save options for the document, may be null to use default set.
|
IOException |
---|
Saves the document even if it hasn't been changed. Note that this may take a while and should not be called on the main thread.
path | Absolute filepath to the output document file. |
---|
IOException |
---|
Saves the document even if it hasn't been changed.
path | Absolute filepath to the output document file. |
---|
Saves the document even if it hasn't been changed.
path | Absolute filepath to the output document file. |
---|---|
saveOptions | Save options for the document. |
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.
saveOptions | Save options for the document. |
---|
true
if the file was modified and changes were saved, false
if there was nothing to save.
IOException |
---|
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.
true
if the file was modified and changes were saved. false
if there was nothing to save.
IOException |
---|
Saves the document to passed 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.
path | Absolute filepath to which to save the document. |
---|
true
if the file was modified and changes were saved, false
if there was nothing to save.
IOException |
---|
Saves the document to passed 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.
path | Absolute filepath to which to save the document. |
---|---|
saveOptions | Save options for the document. |
true
if the file was modified and changes were saved, false
if there was nothing to save.
IOException |
---|
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.
true
if file was saved or false
if there was no changes to be saved.
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.
saveOptions | Save options for the document. |
---|
true
if file was saved or false
if there was no changes to be saved.
Saves the document to passed location if it has been changed. If there were no changes to the document, the document file will not be modified.
path | Absolute filepath to which to save the document. |
---|---|
saveOptions | Save options for the document, may be null to use default set. |
true
if file was saved or false
if there was no changes to be saved.
Saves the document to passed location if it has been changed. If there were no changes to the document, the document file will not be modified.
path | Absolute filepath to which to save the document. |
---|
true
if file was saved or false
if there was no changes to be saved.
Enables or disables automatic link generation. This will parse the PDF page text and automatically generate clickable links (and corresponding
LinkAnnotation
objects) for text that looks like a HTTP or a similar link.
Enabled by default.
enabled | true if link generation should be enabled, false otherwise.
|
---|
Sets the PageBinding
controlling in which direction pages of documents are laid out.
This will be stored in the document metadata and persisted when reopening the document.
pageBinding | The PageBinding to set on the document. |
---|
IllegalArgumentException | Thrown when trying to set the page binding to UNKNOWN .
|
---|
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(SparseIntArray)
.
pageRotation | One of NO_ROTATION , ROTATION_90 , ROTATION_180 , ROTATION_270 . |
---|---|
pageIndex | The page to apply the rotation to. |
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(int, int)
.
pageRotations | A SparseIntArray mapping the page index to the desired rotation.
(One of NO_ROTATION , ROTATION_90 , ROTATION_180 , ROTATION_270 )
|
---|
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.
Affects getPageText(int)
(and overloads), getPageTextLength(int)
and getPageTextRects(int, int, int)
.
Enabled by default.
Returns true
if this document was modified and should be saved to retain changes.
true
if this document was modified and should be saved.