如何在ios应用程序中显示和编辑现有的PDF文件
我不想创建新的 PDF 文件,我已经完成了,但想通过代码在 iOS 中显示和编辑现有的 pdf 文件。
这是否可能,如果可能的话我该怎么做...
更新
假设有一个文本文档pdf,我们想在该文件中输入一些其他文本并保存。那么如何通过编程来做到这一点?
请帮我解决这个问题...
提前致谢...
I do not want to create new PDF file,that I had already done but want to show and edit existing pdf file in iOS through code..
Is this possible or not and if possible than how can I do this...
Update
Suppose there will be text document pdf and we want to enter some other text in that file and save it..so how to do this by programming?
Please help me to solve this problem...
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以通过创建原始 PDF 的副本并在构建过程中对其进行修改来做到这一点。
PS:在我的解决方案中,我需要编辑新PDF的文档信息,所以我使用
执行此操作的 subject 参数。
在Swift 3中
I was able to do this by creating a copy of the original PDF and modifying it during the build process.
PS: In my solution I needed to edit the document info of the new PDF, so I used
the subject parameter to do this.
In Swift 3
我知道这个问题已经太晚了,但我想添加我的解决方案。
我正在使用
UIGraphicsBeginPDFContextToFile
生成 PDF 文件。我从基类UIViewController
创建了一个名为PDFCreator
的类,因为我有两个这样的函数:我在应用程序委托文件中创建了此类的对象,因为它将保留该对象直到应用程序终止(这是我的要求)。
最初,我调用
beginContextWithFile:
,它将在文档目录中创建一个 pdf 文件以及我通过调用createInitialPart
方法添加的数据。在稍后的某个时刻,我需要更新该文件,因此我有另一个名为
secondPart
的方法,尽管我调用它是为了将更多数据附加到该文件中。一旦我完成了创建,我需要调用
PDFCreator
类的endContext
,这将完成 pdf 生成,是的,我将拥有更新的文件。这有点棘手,尽管我有要求,但我没有执行任何内存检查,我找到了解决方案:)
I know its too late for this question, however I'd like to add my solution.
I am using
UIGraphicsBeginPDFContextToFile
to generate a PDF file. I've created a class calledPDFCreator
from base classUIViewController
, in that I have two functions like this:I've created an object of this class in the app delegate file, as it will retain the object until the app terminates (as was my requirement).
Initially, I am calling
beginContextWithFile:
and it will create a pdf file in the document directory along with data I am adding through a call to thecreateInitialPart
method.At some point later I need to update that file, so I have another method named
secondPart
though I called it for some more data to append to that file.Once I fill I've done with the creation, I need to call
endContext
ofPDFCreator
class, that will complete the pdf generation and yes, I will have the updated file.This is little tricky and I didn't perform any memory checks though I had the requirement, I found the solution :)
您可以使用 Quartz2D 来操作 PDF、打开它们、进行转换等。
查看官方 文档
更新:
按照文档中的说明创建 pdf 上下文,然后您只需要写文字:
http://developer.apple.com/library/ios/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101
You can use Quartz2D to manipulate your PDF, open them, make transformation and so on.
Check out the official documentation
Update :
Create your pdf context as explained in the documentation, then you just have to write text :
http://developer.apple.com/library/ios/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101