> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/xamarin/conversion/non-pdf.md).

# Convert to PDF

Learn how to convert non-PDF files to PDF in Xamarin.Android using Apryse SDK. No internet connection needed. Convert office and image files seamlessly. Find out more here! The Apryse Xamarin SDK stre

Apryse SDK allows you to convert non-pdf documents such as office and image files to PDF documents.

{% tabs %}
{% tab title="Android" %}

## Convert to PDF in Xamarin.Android

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .**
{% endhint %}

{% hint style="warning" %}
For Android, available in the full version of the library only. See [Apryse full or standard?](/xamarin/get-started/faq/full-vs-standard.md)
{% endhint %}

{% hint style="info" %}
Internet connection is not required for conversion.
{% endhint %}

{% hint style="info" %}
If you are already using any of [DocumentActivity](/xamarin/guides/android/basics/open.md#activity) or [PdfViewCtrlTabHostFragment2 ](/xamarin/guides/android/basics/open.md#fragment), 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.
{% endhint %}

{% hint style="info" %}
Saving annotations back to non-PDF formats is not supported. You can instead save the annotated PDFDoc to a PDF file.
{% endhint %}

`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](/xamarin/guides/android/basics/open.md#view).

## 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

{% hint style="warning" %}
\*\* Storage Permission \*\*

Please follow the latest Android best practices and guidelines outlined [here](https://developer.android.com/training/permissions/usage-notes/)
{% endhint %}

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

{% code lineNumbers="true" %}

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

{% endcode %}

### 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:

{% code lineNumbers="true" %}

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

{% endcode %}

To monitor the conversion event, do:

{% code lineNumbers="true" %}

```csharp
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
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="iOS" %}

## Convert to PDF in Xamarin.iOS

{% hint style="info" %}
**This tutorial only applies to Xamarin.iOS. See Xamarin.Android equivalent here .**
{% endhint %}

{% hint style="info" %}
Saving annotations back to non-PDF formats is not supported. You can instead save the annotated `PDFDoc` to a PDF file.
{% endhint %}

Apryse has a powerful conversion system which allows you to convert many file formats to PDF. The [`PTConvert`](https://sdk.apryse.com/api/xamarinios/pdfnet/api/pdftron.PDF.Convert.html) class handles the conversion process and supports the following file types:

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

## Open a non-PDF file

The simplest way to convert and view any file format that Apryse supports is to use the [`PTDocumentController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTDocumentController.html) (or [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftron.PDF.Controls.PTTabbedDocumentViewController.html)) method `openDocumentWithURL:`. This method supports local files, files opened from remote cloud services and "raw" `http` URLs.

## Convert a non-PDF file

Another way is to convert a file with the `Convert` class's [`StreamingPDFConversion(String, ConversionOptions)`](https://sdk.apryse.com/api/xamarinios/pdfnet/api/pdftron.PDF.Convert.html#pdftron_PDF_Convert_StreamingPDFConversion_System_String_pdftron_PDF_ConversionOptions_) method. The following code shows how to convert a non-PDF file using Apryse's internal conversion:

{% code lineNumbers="true" %}

```csharp
var documentConversion = Convert.StreamingPDFConversion("my_file_path", null);
documentConversion.Convert();
var pdfDoc = documentConversion.GetDoc();
```

{% endcode %}

The result of the conversion will be contained in the provided `PTPDFDoc`, which can then be [displayed](/xamarin/guides/ios/basics/open.md).

## Convert other non-PDF files

In addition to the file types supported by Apryse's internal conversion, it is also possible to convert many other file types with an iOS-specific API. The `PTConvert` class's [`+convertOfficeToPDF:paperSize:completion:`](https://sdk.apryse.com/api/xamarinios/tools/api/pdftronprivate.PTConvert.html#pdftronprivate_PTConvert_ConvertOfficeToPDF_System_String_CoreGraphics_CGSize_System_Action_Foundation_NSString__) method can convert any file type supported by `WKWebView` to PDF. Some of the supported file types include:

* iWork files: `.pages`, `.key`, `.numbers`
* Binary office files: `.doc`, `.ppt`, `.xls`
* Rich Text Format files: `.rtf`

The following code shows how to convert a file with the iOS-specific API:

{% code lineNumbers="true" %}

```csharp
pdftronprivate.PTConvert.ConvertOfficeToPDF("", CGSize.Empty, (pathToPDF) => { 
    if (pathToPDF == null) {
        // Failed to convert HTML to PDF.
        return;
    }
    var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, false);
    var documentDirectory = dirs[0];

    var urlToPdf = new NSUrl(pathToPDF);
    var destinationURL = (new NSUrl(documentDirectory)).Append(urlToPdf.LastPathComponent, false);

    NSError error = null;
    var result = NSFileManager.DefaultManager.Copy(urlToPdf, destinationURL, out error);
    if (!result) {
        // Failed to copy PDF to persistent location.
    }

    // Do something with PDF output.
});
```

{% endcode %}

## Convert HTML to PDF

Please see [this guide](/xamarin/conversion/conversion/convert-html.md) about Web/HTML to PDF.
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/xamarin/conversion/non-pdf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
