gpt4 book ai didi

ios - 保存解锁 PDFDocumentsRef 到本地目录

转载 作者:可可西里 更新时间:2023-11-01 05:52:45 24 4
gpt4 key购买 nike

我正在我的新 iPhone 应用程序中处理 pdf。我正在检查 PDF 是否被锁定(受密码保护)

BOOL bIsUnlock = CGPDFDocumentIsUnlocked(PDFDocument);

如果pdf被锁定

BOOL success = CGPDFDocumentUnlockWithPassword ( PDFDocument, [password UTF8String]);

这里我成功解锁了文档。现在我想把解锁文档保存到app目录下。

我已经搜索并找到了一个方法

CGPDFPageRef _PDFPage =CGPDFDocumentGetPage(PDFDocument, 1);

CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);

//create empty pdf file;
UIGraphicsBeginPDFContextToFile(newFilePath, pageRect, nil);
size_t count = CGPDFDocumentGetNumberOfPages(PDFDocument);

for (size_t pageNumber = 1; pageNumber <= count; pageNumber++)

{

//get bounds of template page

CGPDFPageRef templatePage = CGPDFDocumentGetPage(PDFDocument, pageNumber);

CGRect templatePageBounds = CGPDFPageGetBoxRect(templatePage, kCGPDFCropBox);

//create empty page with corresponding bounds in new document
UIGraphicsBeginPDFPageWithInfo(templatePageBounds, nil);

CGContextRef context = UIGraphicsGetCurrentContext();

//flip context due to different origins
CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

//copy content of template page on the corresponding page in new file
CGContextDrawPDFPage(context, templatePage);

//flip context back
CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
}
CGPDFDocumentRelease(PDFDocument);

UIGraphicsEndPDFContext();

但我想要任何其他简单的方法,例如将 PDFDocument 转换为NSdata 并保存到目录。请帮忙。

最佳答案

不幸的是,您的代码是将解密的 PDF 文件保存到您的应用程序目录的最简单的解决方案。问题是此代码仅适用于简单的 PDF 文件,因为注释、链接、表单域、书签、文件附件等不会转移到新文档中。这是 CGPDF API 的限制,您无能为力。

关于ios - 保存解锁 PDFDocumentsRef 到本地目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28537008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com