【问题标题】:PDFKIT iOS 11 , Save Annotations Page in PDFDocumentPDFKIT iOS 11,在 PDFDocument 中保存注释页面
【发布时间】:2018-03-06 20:34:00
【问题描述】:

我有一个 PDF 页面,例如 PDF 页面 0。我在页面中更改并添加了一些内容。现在我想保存在 PDFDocument 中。

这是我的代码 这是我的 pdf 文档:

var pdfDocument: PDFDocument?
pdfView.annotationsChanged(on: (pdfView.currentPage)!)

完成这项工作后,pdf 在加载中发生了变化,但重新加载后我得到了 pdf 而没有编辑。

我知道我可以像 pdfDocument?.write(to:) 一样保存,但如果可能的话,我想替换一页而不是全部 pdfDoucment。如果没有,我想用新的变化保存所有页面,比如新的 pdf。

也许我会用这个但是怎么用

pdfDocument?.write(toFile: String, withOptions: [PDFDocumentWriteOption : Any]?)

【问题讨论】:

  • @AamirR 您没有其他解决方案,或者您尝试其他解决方案

标签: swift swift4 ios11 pdfkit


【解决方案1】:

试试这段代码来保存 pdf 内容。我假设您已加载 PDFDocument

NSString *path = @"Name.pdf";
NSString *docsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *newPath = [docsFolder stringByAppendingPathComponent:path];

NSData * content = pdfDocument.dataRepresentation;        
[content writeToFile:newPath atomically:YES];
NSURL *newURL = [NSURL fileURLWithPath:newPath];
pdfdocument = [[PDFDocument alloc] initWithURL:newURL];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    相关资源
    最近更新 更多