Interface WritableDataProvider

  • All Implemented Interfaces:
    com.pspdfkit.document.providers.DataProvider

    
    public interface WritableDataProvider
     implements DataProvider
                        

    WritableDataProvider is an interface which should be implemented by any DataProvider that should support saving PDF documents. Classes implementing this interface must implement all methods from this interface and from DataProvider interface for document loading and saving to work properly.

    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
      public enum WritableDataProvider.WriteMode

      Describes possible write modes for the output.

    • 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 Boolean canWrite() Indicates whether this data provider is writable.
      abstract Boolean startWrite(WritableDataProvider.WriteMode writeMode) Called before writing to the file begins so the provider can prepare file output.
      abstract Boolean write(ByteArray data) Called by PSPDFKit to write data to the document.
      abstract Boolean finishWrite() Called by PSPDFKit after all data has been written via method.
      abstract Boolean supportsAppending() Reports whether this provider supports appending to output file as opposed to always rewriting it.
      • Methods inherited from class java.lang.Object

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

    • Method Detail

      • canWrite

         abstract Boolean canWrite()

        Indicates whether this data provider is writable.

        Returns:

        true if the data provider can be written to, false if not.

      • startWrite

         abstract Boolean startWrite(WritableDataProvider.WriteMode writeMode)

        Called before writing to the file begins so the provider can prepare file output.

        Parameters:
        writeMode - Determines how file data should be written to the output.
        Returns:

        true if operation succeeded, false if writing should be aborted.

      • write

         abstract Boolean write(ByteArray data)

        Called by PSPDFKit to write data to the document. This callback will be called multiple times in a writing operation.

        Parameters:
        data - Data to be written to the file.
        Returns:

        true if writing succeeded, false if the write operation should be aborted.

      • finishWrite

         abstract Boolean finishWrite()

        Called by PSPDFKit after all data has been written via method. This allows the data provider to close all opened input streams. In case of WriteMode.REWRITE_FILE access, the data provider should here replace the original file with the written temporary file.

        Returns:

        true if operation succeeded, false if it failed.

      • supportsAppending

         abstract Boolean supportsAppending()

        Reports whether this provider supports appending to output file as opposed to always rewriting it. If this returns false, only WriteMode.REWRITE_FILE will be used and the PDF file will always be fully rewritten on save.

        Note that if true is returned here, both WriteMode options must be supported by this DataProvider since some documents cannot be saved incrementally.

        Returns:

        true if this provider supports WriteMode.APPEND_TO_FILE save mode.