最近有很多关于绘制PDF的问题.
是的,你可以用UIWebView
很容易地呈现PDF,但这不能提供一个好的PDF查看器所期望的性能和功能.
您可以绘制PDF页面to a CALayer或 to a UIImage.Apple甚至有示例代码来展示如何绘制大型PDF in a Zoomable UIScrollview
但同样的问题不断出现.
UIImage Method:个
- PDF格式的
UIImage
不要光学 可伸缩性以及层次化方法. - 生成时CPU和内存命中
从
PDFcontext
开始的UIImages
限制/阻止使用它创建 实时渲染新的zoom 级别.
CATiledLayer Method:个
- 有相当大的开销(时间)
将整个PDF页面绘制到
CALayer
:可以看到单个平铺的渲染(即使调整了tileSize) -
CALayers
不能提前做好准备 时间(在屏幕外渲染).
一般来说,PDF阅读器的内存也相当大.甚至可以监控苹果可zoom PDF示例的内存使用情况.
In my current project, I'm developing a PDF viewer and am rendering a UIImage
of a page in a separate thread (issues here too!) and presenting it while the scale is x1. CATiledLayer
rendering kicks in once the scale is >1. iBooks takes a similar double take approach as if you scroll the pages you can see a lower res version of the page for just less than a second before a crisp version appears.
Im呈现聚焦页面的每一面2页,以便PDF图像在开始绘制之前准备好遮罩该层.当页面距离焦点页面+2页时,页面再次被销毁.
Does anyone have any insights, no matter how small or obvious to improve the performance/ memory handling of Drawing PDF's? or any other issues discussed here?个
EDIT:个小贴士(Credit-Luke Mcneice,VdesmedT,Matt Gallagher,Johann):
尽可能将任何介质保存到磁盘.
如果在切片图层上渲染,请使用较大的切片大小
使用占位符对象初始化常用数组,或者另一种设计方法是this one
请注意,图像渲染速度将超过
CGPDFPageRef
使用
NSOperations
或GCD&;Blocks页提前准备在
CGContextDrawPDFPage
之前调用CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
以减少绘制时的内存使用量用docRef初始化你的
NSOperations
是个坏主意(内存),把docRef打包成一个单件.如果可以,取消不必要的
NSOperations
,尤其是如果他们将使用内存,请注意不要让上下文处于打开状态!回收页面对象并销毁未使用的视图
在不需要任何打开的上下文时立即将其关闭
收到内存警告时,释放并重新加载DocRef和所有页面缓存
Other PDF Features:个
Getting Raw Text(以及here、Here和here(定位重点))
Searching(和here)(不适用于所有PDF(有些只显示奇怪的字符,我猜是编码问题,但我不确定)-Credit BrainFeed)
CALayer and Off-Screen Rendering-渲染下一页以实现快速/平滑显示
Documentation个
- Quartz PDFObjects(用于元信息、注释、拇指)
- Abobe PDF Spec个
Example projects个
-
Apple/ ZoomingPDF-zoom 、
UIScrollView
、CATiledLayer
-
vfr/ reader-zoom 、分页、
UIScrollView
、CATiledView
- brow/ leaves-具有良好过渡的分页功能
- / skim-一切看起来都一样(OSX的PDF阅读器/编辑器)