phimage / Erik

Erik is an headless browser based on WebKit. An headless browser allow to run functional tests, to access and manipulate webpages using javascript.
http://phimage.github.io/Erik/
MIT License
597 stars 47 forks source link

Question: html -> pdf? #47

Closed marc-medley closed 5 years ago

marc-medley commented 5 years ago

Can Erik be used to generate a PDF file from the rendering of a webpage via either https and/or file url? (preferrably not as a image raster which is then placed into PDF)

phimage commented 5 years ago

maybe try some print to pdf code from https://github.com/appcoda/Print2PDF/blob/master/Print2PDF/InvoiceComposer.swift just get the html from Erik

https://www.appcoda.com/pdf-generation-ios/

marc-medley commented 5 years ago

Thanks for the reply.

To clarify a bit, the quest is to find a Swift Package which could work on various platforms including Linux, macOS and iOS. An example Linux use case would be PDF generation backend for Swift based server side frameworks such as Kitura and Vapor

Apple's proprietary, closed source WKWebView API surprisingly does not print on macOS and unsurprisingly is not available on Linux.

So, while there exists some scriptable HTML to PDF possibilities, a more ideal solution would be an open source Swift Package with can generates PDF files from HTML.

In another wording, would Erik be a candidate to be an open source Swift Package which can generate PDF from HTML that is also portable across any Swift enabled platform? Would such PDF generation make sense as a roadmap feature request?

phimage commented 5 years ago

Erik use WKWebView (if I have time I have project to implement other layout engine like chromium , like selenium use it in python , but no time...)