UrlDataProvider

A data provider that downloads a PDF from a given remote URL.

  • Can be used directly with PdfActivityIntentBuilder.fromDataProvider/PdfActivityIntentBuilder.fromImageProvider for loading and displaying documents.

  • If you just want to load a document you can wrap the data provider into a DocumentSource and pass it to PdfDocumentLoader.openDocument/ImageDocumentLoader.openDocument. You must not do this on the main thread, as the operation would block it until the download is finished. A DownloadException.DownloadOnMainThreadException will be thrown if you try it nonetheless.

We provide 2 options for the download

  • If you pass null for targetFile, the file is downloaded into the a sub folder of the app's cache directory. The cached file will not be reused the next time you open the same URL, but the file will be downloaded again. The OS cleans an app's cache directory when the device is running low on storage, but you can also manually delete the cached files by calling deleteCachedFileForUrl or deleteCachedFiles.

  • If you pass a targetFile, the file referenced by url is downloaded into the given file. This file will be reused the next time you open the same URL. It can be any path that the app has write access to. It's your responsibility to delete this files when they are not needed anymore.

Constructors

Link copied to clipboard
constructor(url: URL, targetFile: File? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun describeContents(): Int
Link copied to clipboard
open override fun getSize(): Long

Return the actual file size of the PDF document which is provided by this data provider. If the data provider can't determine the correct file size (e.g. in case of an error) this method has to return FILE_SIZE_UNKNOWN.

Link copied to clipboard
open override fun getTitle(): String

Displayable document title to be used if PDF document does not contain metadata. For example, for file-based providers this should return the filename. `.pdf` extensions will be stripped automatically.

Link copied to clipboard
open override fun getUid(): String

Unique document identifier used in all caching processes in PSPDFKit. Must be equal or shorter than 50 chars. This method must be implemented for caching to work properly.

Link copied to clipboard
open override fun observeProgress(): Flowable<Double>

Returns an Flowable that emits values from 0 to 1 indicating the current loading progress of this document. You can return ProgressDataProvider.COMPLETE if you don't want to provide progress updates.

Link copied to clipboard
open override fun writeToParcel(dest: Parcel, flags: Int)