Class UrlDataProvider

  • All Implemented Interfaces:
    android.os.Parcelable , com.pspdfkit.document.providers.DataProvider , com.pspdfkit.document.providers.ProgressDataProvider

    
    public final class UrlDataProvider
    extends InputStreamDataProvider implements ProgressDataProvider, Parcelable
                        

    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.

    • Constructor Detail

      • UrlDataProvider

        UrlDataProvider(URL url, File targetFile)
    • Method Detail

      • getSize

         Long getSize()

        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.

        Returns:

        Returns size of PDF document data in bytes, or FILE_SIZE_UNKNOWN in case of an error.

      • getUid

         String getUid()

        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.

        Returns:

        Unique identifier of the provided document. Implementations may not return null or an exception will be thrown.

      • getTitle

         String getTitle()

        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.

        Returns:

        Fallback document title if PDF document does not contain the required metadata. May be null.

      • observeProgress

         Flowable<Double> observeProgress()

        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.