NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

MacOS - Swift - Create PDF File from HTML String

Forums > Swift

During this lockdown I am learning Swift on MacOS and have hit a wall in trying to create a PDF file from an HTML string

I have the HTML string being displayed in a WKWebView, but any attempt to print it or save it to a PDF produces a blank page.

for exampe: -



    let pdf = wkWebView.dataWithPDF(inside: wkWebView.frame)
    let pdfDocument = PDFDocument(data: pdf)
    pdfDocument?.write(toFile: "test.pdf")

Can anyone give me some example code that can produce a PDF from the HTML ?

Many thanks


Have you find a solution ?


Hacking with Swift is sponsored by Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.