iosprintingios5uiprintpagerenderer

UIPrintPageRenderer paperRect always returns 0x0


I've set up printing within my iOS app and it works fine. However, I'm generating my document based on a user preference for the page size. I would expect that I could detect the page size from the printer system and use that instead. The paperRect property of UIPrintPageRenderer seems like just what I need, but it always returns a size of 0x0 for me. Am I missing something? Here's the code:

UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
UIPrintPageRenderer *pageRenderer = [[UIPrintPageRenderer alloc] init];
printController.printPageRenderer = pageRenderer;
NSLog(@"paper size: %f x %f", pageRenderer.paperRect.size.width, pageRenderer.paperRect.size.height);

I tried this when iOS 4.2 came out and when I got 0x0 I figured it was a first-version bug and implemented the user preference. But now that I see the same problem in iOS 5.1 I wonder if I'm doing something wrong.

When this code runs, the user hasn't selected the printer yet, so I would expect the paperRect to return a default paper size. If it runs again after the user selects a printer (e.g., when printing a second document) I would expect it to return the paper size selected for that printer. But this is just my expectation ... the documentation doesn't explain when or how its values are set.

It would be helpful to know if others are getting the same results or if I need to do something else to get a real page size.

P.S. I also looked at the paperSize property of the UIPrintInteractionController, which also returns 0x0 when included with the code above. Apparently it is updated later in the print process by a delegate function, but I didn't explore that further.


Solution

  • paperRect and printableRect is intended to be used in numberOfPages to calculate the number of pages. UIKit won't set any value to paperRect and printableRect until user touches the Print button in UIPrintInteractionController.