public class

OfficeToPdfConverter

extends Object
java.lang.Object
   ↳ com.pspdfkit.document.office.OfficeToPdfConverter

Class Overview

The OfficeToPdfConverter provides a simple API to convert office documents to PDF documents.

The conversion happens by uploading the supplied office document to a running instance of PSPDFKit Server. PSPDFKit Server performs the conversion and then the resulting PDF is downloaded and returned by convertToPdfAsync().

Running the conversion requires the office conversion license on PSPDFKit Server and may take a significant amount of time.

The following file types are supported:

  • Microsoft Word: .doc, .docx
  • Microsoft Excel: .xls, .xlsx
  • Microsoft Powerpoint: .ppt, .pptx

Example usage:

// Grab a JWT token to send to your server to authenticate this client.
 final String jwt = MyServerApi.obtainJwt(fileSha256);

 // Create a OfficeToPdfConverter by passing in the path to the file to convert as well as to your server.
 OfficeToPdfConverter.fromUri(context, Uri.parse("file:///sdcard/my_file.docx"), Uri.parse("http://www.myserver.com/"), jwt)
     .convertToPdfAsync()
     .observeOn(AndroidSchedulers.mainThread())
     .subscribe(file -> {
         // Use the converted PDF.
      );
 }

For more information checkout our office conversion guide article.

Summary

Public Methods
Single<File> convertToPdfAsync()
Performs Office-to-PDF conversion to a temporary file in the application's cache directory.
Completable convertToPdfAsync(File outputFile)
Performs Office-to-PDF conversion to the specified file.
static OfficeToPdfConverter fromUri(Context context, Uri officeDocumentUri, Uri serverUri, String jwt)
Creates an OfficeToPdfConverter from a Uri.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Single<File> convertToPdfAsync ()

Performs Office-to-PDF conversion to a temporary file in the application's cache directory.

This method operates asynchronously on the io() scheduler.

Returns
  • Single emitting file with the converted PDF or an error if conversion failed.

public Completable convertToPdfAsync (File outputFile)

Performs Office-to-PDF conversion to the specified file.

This method operates asynchronously on the io() scheduler.

Parameters
outputFile Output file to write the converted PDF to.
Returns
  • Completable emitting completion if PDF conversion finished or an error if conversion failed.

public static OfficeToPdfConverter fromUri (Context context, Uri officeDocumentUri, Uri serverUri, String jwt)

Creates an OfficeToPdfConverter from a Uri. Supported URIs are:

  • URIs with scheme "file://" pointing to a file in the filesystem.
  • URIs with scheme "file:///android_asset/" pointing to the application assets, in this case a temporary file is used.
  • URIs with scheme "content://", in this case the data returned by the content provider will first be copied to a temporary file before being uploaded to the server. In case this is undesirable use a "file://" URI to ensure no temporary files are created.

Parameters
context The context to use.
officeDocumentUri URI pointing to the office file to convert.
serverUri The URI of the server that will perform the conversion.
jwt A JWT containing the SHA-256 of the office file that will be converted. Used to authenticate access to the server.