Generating a PDF using the new printing stuff in iOS 4.2

删除回忆录丶 提交于 2019-11-28 17:40:32

It seems as though print formatters (including UIMarkupTextPrintFormatter) aren't actually rendered/drawn until right before printing, once the system takes over and starts the print job. (Apple's docs say drawRect: is called right before printing to provide the content for the print job.)

Someone please prove me wrong because I need to do basically the same thing :)

TomSwift

I do this in one of my apps. See my answer to a similar question, here:

Is there any way to generate PDF file from a XML/HTML template in iOs

I made a discovery: this is possible, if you're willing or allowed to use private API. (e.g., in an enterprise app.)

The method: create your formatter as usual; install it in a UIPrintPageRenderer.

Set the renderer's private properties paperRect and printableRect appropriately.

numberOfPages now works!

Set up your pdf cgcontext like normal, and draw the page with the renderer's drawPageAtIndex:inRect: method. Holy cow, it worked.

Obligatory protestation: yes, I know Apple doesn't want you submitting apps that call (e.g.) [ppr setValue:[NSValue valueWithCGRect:page] forKey:@"paperRect"]; and will bounce them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!