我正在我的新 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
并保存到目录。请帮忙。