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

# Convert documents to PDF on iOS

Convert and save annotations with Apryse's powerful conversion system. Learn how to convert various file formats to PDF effortlessly. Explore the PTConvert class for seamless file conversion. The Apry

{% 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/ios/Classes/PTConvert.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/ios/Classes/PTDocumentController.html) (or [`PTTabbedDocumentViewController`](https://sdk.apryse.com/api/ios/Classes/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 `PTConvert` class's [`+ToPDF:in_filename:`](https://sdk.apryse.com/api/ios/Classes/PTConvert.html#/c:objc\(cs\)PTConvert\(cm\)ToPdf:in_filename:) method. The following code shows how to convert a non-PDF file using Apryse's internal conversion:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Create empty PDFDoc.
let doc = PTPDFDoc()

// Convert non-PDF file at "my_file_path"
PTConvert.toPdf(doc, in_filename: "my_file_path")
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Create empty PDFDoc.
PTPDFDoc *doc = [[PTPDFDoc alloc] init];

// Convert non-PDF file at "my_file_path".
[PTConvert ToPdf:doc in_filename:@"my_file_path"];
```

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

The result of the conversion will be contained in the provided `PTPDFDoc`, which can then be [displayed](/ios/basic-operations/open/view.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/ios/Classes/PTConvert.html#/c:objc\(cs\)PTConvert\(cm\)convertOfficeToPDF:paperSize:completion:) 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="Swift" %}
{% code lineNumbers="true" %}

```swift
PTConvert.convertOffice(toPDF: "my_file_path", paperSize: .zero) { (pathToPDF) in
    guard let pathToPDF = pathToPDF else {
        // Failed to convert file to PDF.
        return
    }
    
    // Copy temporary PDF to persistent location.
    let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, false)[0]
    
    let urlToPDF = URL(fileURLWithPath: pathToPDF)
    let destinationURL = URL(fileURLWithPath: documentDirectory).appendingPathComponent(urlToPDF.lastPathComponent)
    
    do {
        try FileManager.default.copyItem(at: urlToPDF, to: destinationURL)
    } catch {
        // Failed to copy item to persistent location.
    }

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

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
[PTConvert convertOfficeToPDF:@"my_file_path" paperSize:CGSizeZero completion:^(NSString *pathToPDF) {
    if (!pathToPDF) {
        // Failed to convert file to PDF.
        return;
    }
    
    NSString *documentDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO)[0];
    
    // Copy temporary PDF to persistent location.
    NSURL *urlToPDF = [NSURL fileURLWithPath:pathToPDF];
    NSURL *destinationURL = [[NSURL fileURLWithPath:documentDirectory] URLByAppendingPathComponent:urlToPDF.lastPathComponent];
    
    NSError *error = nil;
    BOOL result = [NSFileManager.defaultManager copyItemAtURL:urlToPDF toURL:destinationURL error:&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](/ios/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/ios/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.
