Some test text!

Web/HTML to PDFkeyboard_arrow_down

Convert HTML to PDF on iOS

Internet connection is not required when converting local HTML files. However, it is required for converting HTTP/HTTPS links.

The platform-specific conversion API also supports HTML to PDF conversion, either with the +convertOfficeToPDF:paperSize:completion: method for .html files or the +convertHTMLStringToPDF:baseURL:paperSize:completion: for raw HTML text.

The following code shows how to convert an HTML string to PDF:

PTConvert.convertHTMLString(toPDF: htmlString, baseURL: baseURL, paperSize: .zero) { (pathToPDF) in
    guard let pathToPDF = pathToPDF else {
        // Failed to convert HTML to PDF.
    // 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.

where baseURL is the URL to use as the page's base URL for resolving relative links in the document.

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our upcoming webinar to learn about how to collaborate on videos frame by frame directly in your browser

Save your seat