简体   繁体   English

在ios中将视图内容添加到pdf页面到pdf

[英]Add view contents to pdf page to pdf in ios

I want to add the contents of the view to pdf at a preferred position on my pdf page.Right now i am using 我想将视图的内容添加到pdf页面上首选位置的pdf中。现在我正在使用

[printview.layer renderInContext:UIGraphicsGetCurrentContext()];

which cannot satisfy my requirement of adding to the specific position in the pdf page.Anybody have some workaround??please explain. 这不能满足我在pdf页面中添加特定位置的要求。任何人都有一些解决方法?请解释一下。 I know about the documentation available .gone through it .but need help. 我知道通过它可用的文档。但是需要帮助。

also what to do if i need to add two views in the same pdf page generated by the same view ?? 如果我需要在同一视图生成的同一pdf页面中添加两个视图,该怎么办?

thanks in advance :) 提前致谢 :)

This code allows you to define a rect in which the pdf is drawn: 此代码允许您定义在其中绘制pdf的矩形:

const CGRect mediaBox = CGRectMake(0.0f, 0.0f, drawingWidth, drawingHeight);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &mediaBox, NULL);

If you need more help, just ask. 如果您需要更多帮助,请询问。

I'd suggest you render the pdf into a UIImage, then it's easy to move it around/animate it as you wish. 我建议您将pdf渲染到UIImage中,然后根据需要轻松地将其移动/动画化。 Of course then you looks the benefit of pdf, that it is zoomable, so you could combine a UIImageView and a CATiledLayer. 当然,您会看到pdf的好处,因为它是可缩放的,因此可以将UIImageView和CATiledLayer结合在一起。

I did exactly that in a commercial iOS library. 我正是在商业iOS库中做到了这一点。 My class is called PSPDFPageView and uses both the image and the tiled layer to have both a fast display (image) and great zooming (CATiledLayer). 我的班级称为PSPDFPageView,它同时使用图像和平铺图层来具有快速显示(图像)和出色的缩放(CATiledLayer)功能。 Of course, for the zooming to work you need to put that into a [scrollview][3] too. 当然,要使缩放正常工作,您还需要将其放入[scrollview] [3]。

w/o more code I can't help you further on this, but you now should get the idea on how to build sth like this. 没有更多代码,我无法进一步帮助您,但是您现在应该就如何构建这样的东西了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM