我有一个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]?)发布于 2019-01-16 05:05:19
尝试这段代码来保存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];https://stackoverflow.com/questions/49139509
复制相似问题