Some test text!
iOS / Guides / Convert to PDF
PDFDoc to a PDF file.Apryse has a powerful conversion system which allows you to convert many file formats to PDF. The PTConvert class handles the conversion process and supports the following file types:
.docx, .pptx, .xlsx, .doc (with the office conversion Add-On module).bmp, .jpg, .tif, .png, .gif.md (with the office conversion Add-On module)The simplest way to convert and view any file format that Apryse supports is to use the PTDocumentController (or PTTabbedDocumentViewController) method openDocumentWithURL:. This method supports local files, files opened from remote cloud services and "raw" http URLs.
Another way is to convert a file with the PTConvert class's +ToPDF:in_filename: method. The following code shows how to convert a non-PDF file using Apryse's internal conversion:
// Create empty PDFDoc.
let doc = PTPDFDoc()
// Convert non-PDF file at "my_file_path"
PTConvert.toPdf(doc, in_filename: "my_file_path")The result of the conversion will be contained in the provided PTPDFDoc, which can then be displayed .
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: method can convert any file type supported by WKWebView to PDF. Some of the supported file types include:
.pages, .key, .numbers.doc, .ppt, .xls.rtfThe following code shows how to convert a file with the iOS-specific API:
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.
}Please see this guide about Web/HTML to PDF.
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales