PDF with Webview

I am looking for some help in creating a PDF document. Currently I have a web view which contains labels to show my data. Does anyone have any advice and/or tutorials I could reference for help? Thank you!

@jport1130 Thanks very much for your question!

I did find the following tutorial on another site which might be of benefit to you.

Here is another tutorial that might be helpful.

I hope this helps!

All the best!

Thank you! I have been making some progress, but seem to have an issue and have been receiving this error…Use of unresolved identifier ‘drawPDFUsingPrintPageRenderer’

func exportHTMLContentToPDF(HTMLContent: String) {
let printPageRenderer = CustomPrintPageRenderer()

    let printFormatter = UIMarkupTextPrintFormatter(markupText: HTMLContent)
    printPageRenderer.addPrintFormatter(printFormatter, startingAtPageAt: 0)
    
    let pdfData = drawPDFUsingPrintPageRenderer(printPageRenderer)
    
    pdfFilename = "\(AppDelegate.getAppDelegate().getDocDir())/Invoice\(invoiceNumber).pdf"
    pdfData.writeToFile(pdfFilename, atomically: true)
    
    print(pdfFilename)
}

hi @jport1130,
You have looked at the code in the article but not looked to the next section where the function drawPDFUsingPageRenderer is declared. Once you add that to your project, that should not give you an error.

cheers,

Jayant

Thank you for your help!

I have been receiving the following error: Cannot convert value of type ‘[NSAttributedStringKey : Any]’ to type ‘[String : AnyObject]!’ in coercion

let textAttributes = [NSFontAttributeName: font!, NSForegroundColorAttributeName: UIColor(red: 243.0/255, green: 82.0/255.0, blue: 30.0/255.0, alpha: 1.0), NSKernAttributeName: 7.5]

Hi @jport1130, you could try [NSAttributedStringKey: Any] . Should remove the error.

let textAttributes = [NSAttributedStringKey.font.rawValue: font!, NSAttributedStringKey.foregroundColor: UIColor(red: 243.0/255, green: 82.0/255.0, blue: 30.0/255.0, alpha: 1.0), NSAttributedStringKey.kern: 7.5] as! [NSAttributedStringKey: Any]

Best,
Gina

Thank you, I appreciate the help!!!

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.