使用 CGPDFDocumentRef 的 PDF 阅读器
我要做一个 PDF 阅读器,我正在尝试两种可能的解决方案:
- UIWebView
- CGPDFDocumentRef
第一个非常简单,但比第二个慢。 对于第二个,我找到了一个教程,我可以查看 pdf,并且可以用两根手指的移动来缩放它。但目前我不能做两件事:
1)以横向模式查看 PDF,保持正确的比例。 2)双击屏幕进行放大/缩小。
这些功能已经在 UIWebView 中实现了,但是前面说过,它有点慢,而且它打开整个 PDF 文档,而不仅仅是单个页面(所以我需要将文件拆分为许多“一页 pdf 文件”)。
任何人都可以帮助我提供有关此类问题的一些链接/参考资料/代码吗?
i'm going to make a PDF reader and i'm trying two possible solutions:
- UIWebView
- CGPDFDocumentRef
The first one is very simple, but is slower than the second one.
For the second one, i found a tutorial and i can view a pdf and i can zoom it with the two fingers movement. But at the moment i can't do 2 things :
1) View the PDF in landscape mode, maintaining the correct proportions.
2) Do a zoom in / zoom out with the double tap on the screen.
Those functions are already implemented in the UIWebView, but how said before, it's a little bit slow and it opens the entire PDF doc and not only a single page (so i need to split the file in many "one page pdf files").
Anyone can help me with some links/references/code about those kind of problems ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
CGPDFDocumentRef
,您需要使用CGPDFDocumentGetPage
获取每个页面,然后使用CGPDFPageGetDrawingTransform
获取绘图转换并将其应用到CGContextRef< /code> 在绘制页面之前。
如果启用缩放功能,则将 PDF 页面的视图放入 UIScrollView 中可以放大和缩小。您还可以使用缩放系数来绘制它,
但是您仍然会遇到非常复杂的 PDF 页面渲染速度很慢的问题,并且每次调用 CGContextDrawPDFPage(context, page); 时都会遇到问题必须渲染整个页面,例如当您更改缩放级别时。有很多方法可以解决这个问题,例如绘制到 CATiledLayer 中。
With
CGPDFDocumentRef
, you need to get each page withCGPDFDocumentGetPage
and then get the drawing transform withCGPDFPageGetDrawingTransform
and apply that to theCGContextRef
before you draw the page.Putting the view with your PDF page in a UIScrollView will let you zoom in and out, if you enable zooming. You can also draw it with a zoom factor using
But you'll still run into the issue that very complex PDF pages will be slow to render, and every time you call
CGContextDrawPDFPage(context, page);
it has to render the entire page, such as when you change the zoom level. There are ways around this, such as drawing into a CATiledLayer.确切地说,在我找到的示例中,他使用了 CATiledLayer。
这是我的代码:
这部分效果很好,但是如果我想引入横向模式,我需要修改这部分:
我尝试了几乎所有的方法,但我找不到好的解决方案!
Exactly, in the example that i found, he uses the CATiledLayer.
Here there is my code:
This part works great, but if i want to introduce the landscape mode, i need to modify this part:
I tried pratically everything, but i can't find a good solution !
您可以通过以下方式手动调用任何图层的绘制图层方法
[你的图层设置需要显示]
you can call draw layer method of any layer manually by saying
[yourLayer setNeedsDisplay]