Reputation: 1081
A part of my application involves printing PDF's which are loaded into a UIWebView.
The code I am using to airprint these PDF's loaded in my UIWebView was working fine for iOS version 6. Since the iOS7 update, my pages still print using the same code on my app, however several issues are present as listed:
An additional empty page is being printed with every print. If my PDF document is 2 pages long, the printer will print 2 pages with the PDF content and an additional 3rd page which is blank. This is not of great concern to me, since no ink or paper is wasted, however it is a bit sloppy for the solution I'm trying to implement.
The main problem I am exepriencing is that after the iOS7 update, the same code which was working fine on iOS 6 iPad/iPhone devices now is broken. The code allows me to print the full content of the PDF's, however the content is scaled down to 50% of total paper area (which in my case is a portrait letter sized paper).
Despite positing on apple's development website, I was unable to get any response from their forum members.
Here is the code I am using:
-(void) printWebView:(UIWebView *)webView {
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange= NO;
UIPrintPageRenderer *renderer = [[UIPrintPageRenderer alloc] init];
webView.viewPrintFormatter.printPageRenderer.headerHeight = 30.0f;
webView.viewPrintFormatter.printPageRenderer.footerHeight = 30.0f;
webView.viewPrintFormatter.contentInsets = UIEdgeInsetsMake(0.0f, 30.0f, 0.0f, 30.0f);
webView.viewPrintFormatter.startPage = 0;
[renderer addPrintFormatter:webView.viewPrintFormatter startingAtPageAtIndex:0];
pic.printPageRenderer = renderer;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
// indicate done or error
}];
Has anyone else experienced this issue, and is there a solution, or is this a legitimate issue that Apple needs to fix in their next update?
Also, while it seems unlikely to me, could an non-current version (1 version old) of Xcode be causing the issue?
Upvotes: 3
Views: 863
Reputation: 108
I have observed the same issue under iOS 7. The only solutions I have been able to come up with is to either set the UIPrintInteractionController's printingItem to a URL pointing to the desired PDF, or to set the printingItem to an NSData representation of the PDF rather than setting the printFormatter property. I had some issues using printingItem under iOS 5, so I had a fallback solution such as below.
// Work around for printing item not working with our document URL under iOS 5.
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
printController.printingItem = self.documentURL;
}
else
{
printController.printFormatter = [self.webView viewPrintFormatter];
}
Upvotes: 1