eNc
eNc

Reputation: 1081

iOS7 Update - Airprinting PDF loaded in UIWebView yields scaled PDF to 50% of letter page size

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:

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

Answers (1)

slpaulson
slpaulson

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

Related Questions