我在PDF页面0中有一个PDF页面。我在页面中更改并添加了一些内容。现在我要保存在PDFDocument中。
这是我的代码 这是我的pdf文件:
var pdfDocument: PDFDocument?
pdfView.annotationsChanged(on: (pdfView.currentPage)!)
完成这项工作后,pdf更改为In Load但重新加载后我没有编辑而没有pdf。
我知道我可以像pdfDocument?.write(to:)
一样保存,但是如果可能的话,我想要替换一页而不是全部pdfDoucment。如果没有,我想保存所有页面,如新的pdf。
也许我会用这个但是怎么用
pdfDocument?.write(toFile: String, withOptions: [PDFDocumentWriteOption : Any]?)
答案 0 :(得分:0)
尝试这段代码以保存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];