I am creating a multi-page html document that I would like to send to an Airprint printer from my application. Each page is discrete and should start with its own sheet.
It should be relatively simple - the content of each page is immediately followed by a div
element that has display: block; page-break-after: always;
display: block; page-break-after: always;
. Here is a simple example:
<html> <head> <title>Printing with Page Breaks</title> <style type="text/css"> @media screen or print { div.pageb { display: block; page-break-after: always; } } </style> </head> <body> <h1>Page 1</h1> <p>Lorem ipsum dolor sit amet...</p> <div class="pageb"></div> <h1>Page 2</h1> <p>Lorem ipsum dolor sit amet...</p> <div class="pageb"></div> <h1>Page 3</h1> <p>Lorem ipsum dolor sit amet...</p> <div class="pageb"></div> </body> </html>
This document prints perfectly from Safari and Chrome, which place all page breaks where they should be. However, on iOS, page breaks are not inserted.
To print the html, I use the UIPrintInteractionController
to print the contents of the UIWebView
using the UIViewPrintFormatter
. Something like that:
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; controller.printInfo = printInfo; UIWebView *webViewPrint = [[UIWebView alloc] init]; [webViewPrint loadHTMLString:printHTML baseUrl:@"/"]; UIViewPrintFormatter *viewFormatter = [webViewPrint viewPrintFormatter]; controller.printFormatter = viewFormatter; controller.showsPageRange = NO; [controller presentAnimated:YES completionHandler:completionHandler];
All this seems very standard, and I can only wonder why page breaks print correctly in other Webkit browsers, but not in UIWebView. Any ideas on how to make page breaks in iOS?
source share