Interface DataProvider

  • All Implemented Interfaces:

    
    public interface DataProvider
    
                        

    A data provider is allows PSPDFKit to load a PDF document for any custom source (e.g. cloud providers, files, in-memory, data providers, etc.).

    Classes implementing this interface need to implement all methods correctly to allow PSPDFKit loading documents. Furthermore, if classes with this interface are meant to be used with PdfActivity, they must also implement android.os.Parcelable. If you plan to use the DataProvider only for PdfFragment parcelation code is not necessary.

    All callbacks will be called on a background thread.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Array<byte> read(long size, long offset) Called by PSPDFKit to read data from the document.
      abstract long getSize() Return the actual file size of the PDF document which is provided by this data provider.
      abstract String getUid() Unique document identifier used in all caching processes in PSPDFKit.
      abstract String getTitle() Displayable document title to be used if PDF document does not contain metadata.
      abstract void release() Called when the provided document is being closed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • read

        @NonNull() abstract Array<byte> read(long size, long offset)

        Called by PSPDFKit to read data from the document. The returned byte array can be reused in subsequent calls to prevent excessive allocations.

        Parameters:
        size - Size of the data chunk to be read in bytes.
        offset - Offset from start of document of the data chunk to be read in bytes.
        Returns:

        Byte array with document data of the exact same size or larger size than size parameter. Implementations may not return null or loading will fail. Instead, when experiencing a read error, implementations may return NO_DATA_AVAILABLE to safely stop reading.

      • getSize

         abstract 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

        @NonNull() abstract 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

        @Nullable() abstract 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.

      • release

         abstract void release()

        Called when the provided document is being closed. Implementations are expected to release all resources (like closing of all streams and freeing of allocations).