> 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/conversion/convert-to-pdf.md).

# Convert documents to PDF in Xamarin

Learn how to convert non-PDF files to PDF using Xamarin.iOS. Explore Apryse's powerful conversion system supporting various file types like Office, images, markdown, and more. Optimize your file viewi

{% 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:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

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

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

{% tabs %}
{% tab title="C#" %}
{% 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 %}
{% endtab %}
{% endtabs %}

## Convert HTML to PDF

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


---

# 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/conversion/convert-to-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.
