So I had this problem too. I was using a UIWebView to access a website link which opened a PDF document in the window. When the PDF was printing, the document was getting cropped at the bottom and sent to the next page. This was annoying because now a two page PDF document was printing as a three page PDF document with basically nothing on the third page. My fix was simple I did two things. I have not tested if both of these things are necessary to fix this problem however I will post both anything.
In this method in my ViewController.m:
- (void) webViewDidStartLoad:(UIWebView *)webView
{
webView.scalesPageToFit = YES;
}
and then in my printing method (I have a method to print since I have multiple scenes with webviews and print buttons.
-(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
}];
}
Now I don't know if all that is necessary for you application but the lines I added which helped me with my scaling problem are
webView.scalesPageToFit = YES;
and
pic.showsPageRange= NO;
This may seem a bit odd but from what I've read, the
pic.showsPageRange= NO;
is the key here. If this were set to yes, XCode AirPrint would scale the paged all screwy and your margins would get all messed up like mine did with my PDF loaded inside my webview. I actually read this on StackOverflow, and would like to credit the author of the post answer but I am having some difficulty locating his post. This seems like a bit of a trade off, as the print dialog will no longer show the page range for the document being printed, however for short documents, I personally think its worth the tradeoff for the simplicity of implementing a scaled document print vs a lengthy workaround.
Anyways, I hope this works for you, and if you find something better let us know.
PS I know my code for formatting/rendering is all messed up, I was trying to figure out how I could manipulate the printing options in XCode and have not deleted unnecessary lines yet.