Some test text!

platform
search

Convert documents to PDF

Contents

View a document
Option 1: from local device storage
Option 2: from content uri
This tutorial only applies to Xamarin.Android.
Conversion requires full version of PDFTron library. See PDFTron full or standard?
If you are already using any of DocumentActivity or PdfViewCtrlTabHostFragment, you will not need to go through this article as viewing of 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

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.

linkView a document

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

linkOption 1: from local device storage

To access device storage, add the following permissions to AndroidManifest.xml file in the <manifest> tag (outside of the <application> tag):

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

var nonPdfUri = Android.Net.Uri.FromFile(new Java.IO.File("my_file_path"));
var documentConversion = pdfViewCtrl.OpenNonPDFUri(nonPdfUri, null);

linkOption 2: from content uri

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

var nonPdfContentUri = Android.Net.Uri.Parse("my_content_uri");
var documentConversion = pdfViewCtrl.OpenNonPDFUri(nonPdfContentUri, null);

To monitor the conversion event, do:

pdfViewCtrl.UniversalDocumentConversion += (sender, e) =>
{
    if (e.State == PDFViewCtrl.ConversionState.Progress)
    {
        // conversion in progress
    }
    else if (e.State == PDFViewCtrl.ConversionState.Finished)
    {
        // conversion finished successfully
    }
    else if (e.State == PDFViewCtrl.ConversionState.Failed)
    {
        // conversion failed
    }
}

Get the anwsers you need: Support

Contents

View a document
Option 1: from local device storage
Option 2: from content uri