Print a WebView content on duplex (front and back) printer with different margins for front and back

145 Views Asked by At

I have a WebView, and want to print it's HTML content via AirPrint. I want to add custom page margins to this content. I was able to achieve it using my own subclass of UIPrintPageRenderer

Now, whenever my app user is using duplex printer (printing front and back of the page), I want to set different page margins for front page and back page.

UIPrintPageRenderer was not able to achieve this task, since it asks for headerHeight, footerHeight as a single property and it does not have something like headerHeight(forPage:)

I also explored option of creating PDF file, but apparently PDF files are generated using UIPrintPageRenderer only.

Also, I don't know how to override or get custom UIViewPrintFormatter from WKWebView, since this object is returned by WebView's function func viewPrintFormatter() -> UIViewPrintFormatter

0

There are 0 best solutions below