Open MS Office documents and convert to PDF in Android

For Android, available in the full version of the library only. See Apryse full or standard?

Internet connection is not required for conversion.

If you are already using any of DocumentActivity or PdfViewCtrlTabHostFragment2 , you will not need to go through this article as viewing other document types is already taken care of internally. Continue reading this article if you are not planning to use any of the above.

Saving annotations back to non-PDF formats is not supported. You can instead save the annotated PDFDoc to a PDF file.

PDFViewCtrl has a powerful and seamless conversion system which allows you to stream documents during conversion to PDF. It supports the following file types:

  • Office file conversion: .docx, .pptx, .xlsx, .doc. (with the office conversion Add-On module)
  • Image conversion: .bmp, .jpg, .tif, .png, .gif
  • Image collections (zip archives with any type of image listed above)
  • Markdown: .md (with the office conversion Add-On module)

In this tutorial you will be able to display a non-PDF file in PDFViewCtrl.

Before going forward, please make sure you have finished setting up PDFViewCtrl as described in Using PDFViewCtrl.

View a document

The easiest way to display a non-PDF file in PDFViewCtrl is through the PDFViewCtrl.openNonPDFUri API.

Option 1: from local device storage

Storage Permission

Please follow the latest Android best practices and guidelines outlined here

Add the following when you would like to show the document, typically onCreate or onResume of your Activity or Fragment:

1try {
2 Uri nonPdfUri = Uri.fromFile(new File("my_file_path"));
3 DocumentConversion documentConversion = pdfViewCtrl.openNonPDFUri(nonPdfUri, null);
4} catch (Exception ex) {
5 ex.printStackTrace();
6}

Option 2: from content uri

Add the following when you would like to show the document, typically onCreate or onResume of your Activity or Fragment:

1try {
2 Uri nonPdfContentUri = Uri.parse("my_content_uri");
3 DocumentConversion documentConversion = pdfViewCtrl.openNonPDFUri(nonPdfContentUri, null);
4} catch (Exception ex) {
5 ex.printStackTrace();
6}

To monitor the conversion event, do:

1pdfViewCtrl.addUniversalDocumentConversionListener(new PDFViewCtrl.UniversalDocumentConversionListener() {
2 @Override
3 public void onConversionEvent(PDFViewCtrl.ConversionState state, int totalPagesConverted) {
4 switch (state) {
5 case PROGRESS:
6 // conversion in progress
7 break;
8 case FINISHED:
9 // conversion finished successfully
10 break;
11 case FAILED:
12 // conversion failed
13 if (documentConversion != null) {
14 try {
15 Log.e("MainActivity", "Conversion failed: " + documentConversion.getErrorString());
16 } catch (Exception ignored) {}
17 }
18 break;
19 }
20 }
21});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales