Wrong paper size in AirPrint

1.6k Views Asked by At

In my app, different photo sizes can be printed. This is working fine, but with iOS 8 the paper size is always letter/A4 even if the print dialog display e.g.. 5"x7". If the user selects the paper size again, the paper size changes to e.g. 5"x7".

Does anybody have the same problem?

Is there a workaround?

Here is the code:

 - (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList

 {
    CGSize PageSize = ((PPPage *)[document.pages objectAtIndex:0]).paperSize;

    if (PageSize.width > PageSize.height) {
        float w = PageSize.width;
        PageSize.width = PageSize.height;
        PageSize.height = w;
    }
    NSLog(@"printInteractionController:choosePaper: Needed Pagesize = (%.1f,%.1f)",PageSize.width,PageSize.height);
    UIPrintPaper *retPaper = [UIPrintPaper bestPaperForPageSize:PageSize withPapersFromArray:paperList];
    NSLog(@"printInteractionController:choosePaper: chosen UIPrintPaper = (%.1f,%.1f)",retPaper.paperSize.width,retPaper.paperSize.height);

    return retPaper;
}

And the log output:

2015-06-19 12:22:53.474 PhotoPrint[5955:1225053] printInteractionController:choosePaper: Needed Pagesize = (288.0,432.0) 2015-06-19 12:22:54.118 PhotoPrint[5955:1225053] printInteractionController:choosePaper: chosen UIPrintPaper = (612.0,792.0) 2015-06-19 12:22:54.118 PhotoPrint[5955:1225053] -[PKPaperList matchedPaper:preferBorderless:withDuplexMode:didMatch:] paperToMatch= result= matchType=0 2015-06-19 12:23:06.351 PhotoPrint[5955:1225053]

--> wrong paper size letter selected!


Now select the paper again:

printInteractionController:choosePaper: Needed Pagesize = (288.0,432.0) 2015-06-19 12:23:14.860 PhotoPrint[5955:1225053] printInteractionController:choosePaper: chosen UIPrintPaper = (360.0,504.0) 2015-06-19 12:23:14.860 PhotoPrint[5955:1225053] -[PKPaperList matchedPaper:preferBorderless:withDuplexMode:didMatch:] paperToMatch= result= matchType=0

--> this time correct paper size.

1

There are 1 best solutions below

0
On

Your code appears to be swapping width and height -- it seems you are attempting to change the orientation of the print. That's not the way to do it: to set orientation, see UIPrintInfo.orientation

As to why you sometimes get different results, i'm not sure but I assume that bestPaperForPage size can be affected by the selected printer's offline/online state (ie. if you call bestPaperForPage before the printer has ever been contacted, it will default to A4 unless you have chosen Photo print type). If you want the default to be 4x6 then use UIPrintInfoOutputPhoto on your UIPrintInfo