开发者

Is it possible to control top & bottom page margins when using UIMarkupTextPrintFormatter?

开发者 https://www.devze.com 2023-02-08 13:07 出处:网络
I\'m trying to use the printing stuff in iOS 4.2 to print from my iPhone app, but I\'m having real trouble getting multi-page content to display nicely.As you can see in the attached screenshots of PD

I'm trying to use the printing stuff in iOS 4.2 to print from my iPhone app, but I'm having real trouble getting multi-page content to display nicely. As you can see in the attached screenshots of PDFs generated through the iOS printing API, UIMarkupTextPrintFormatter really likes to use a painfully small top-margin when rendering.

Additionally, it doesn't seem to try to split block-elements too nicely either ... it's tough to see in the screenshot but the page break actually occurs halfway through a table row, rather than on a border between rows.

I've tried using the CSS @page directives to specify page boundaries, however iOS Webkit doesn't seem to support these at all.

Does anyone know of any techniques, either in HTML or through the iOS SDK to make these top-margins bigger?

I really don't want to write a custom UIPrin开发者_如何学PythontPageRenderer class because I'm trying to give my users the ability to customize their printouts through HTML templates ... going with a custom renderer would almost certainly make this impossible (or really difficult).

Any help is much appreciated!

Is it possible to control top & bottom page margins when using UIMarkupTextPrintFormatter?


You're on the right track with UIPrintPageRenderer, but fortunately you don't need to write a custom subclass to do this. All you need to do is instantiate a vanilla UIPrintPageRenderer, set the headerHeight and footerHeight properties, and add your HTML formatter to the renderer using addPrintFormatter:startingAtPage:. It only takes a few extra lines of code, I have posted my method here: Print paper size and content inset

0

精彩评论

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