开发者

iOS printing a PDF via printingItem appears to add a blank header; can it be removed?

I am using iOS 4.3 and Apple's suggested method for printing a PDF, which is to set the shared UIPrintInteractionController's printingItem property to an NSData object containing PDF data. It's very easy, which is great, but I've found that when printing a PDF via this method, the content starts 4mm lower on the page than if I print via Preview.app on my Mac. As I am printing to pre-cut labels, precise positioning is important.

It appears that somewhere in the process, a (blank) header is being added to the page, which is causing the content to shift down the page. The resulting horizontal margins are the same on both iOS and Mac OS X so I suspect it really is a header, and not an all-around margin.

I have checked the following:

  • Is the printer adding the header? No, because the same results can be seen when printing to the Printer Simulator.
  • Is the iPad using a different paper size to the Mac? I have used开发者_JS百科 the delegate method to ensure that the UIPrintPaper is the same for both.
  • Can I edit headerHeight for the UIPrintPageRenderer? No, because a renderer is not created when setting a printing item directly.

My workaround is to make the PDF generator (the server) create the PDF content 4mm higher up than it ought to be, but this breaks printing from Mac OS.

Out of ideas now! Thanks for any assistance.


You should check Apple's sample code PrintWebView. I believe the problem your having is because of the hardware margins. See SIMPLE_LAYOUT constant in PrintWebView sample to learn more. Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜