I am working on pdf in my new iPhone app. I check that the PDF is locked (password protected) or not
BOOL bIsUnlock = CGPDFDocumentIsUnlocked(PDFDocument);
If the PDF file is locked, then
BOOL success = CGPDFDocumentUnlockWithPassword ( PDFDocument, [password UTF8String]);
Here I manage to unlock documents. Now I want to save the unlock document in the application directory.
I searched and found a way
CGPDFPageRef _PDFPage =CGPDFDocumentGetPage(PDFDocument, 1);
CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);
UIGraphicsBeginPDFContextToFile(newFilePath, pageRect, nil);
size_t count = CGPDFDocumentGetNumberOfPages(PDFDocument);
for (size_t pageNumber = 1; pageNumber <= count; pageNumber++)
{
CGPDFPageRef templatePage = CGPDFDocumentGetPage(PDFDocument, pageNumber);
CGRect templatePageBounds = CGPDFPageGetBoxRect(templatePage, kCGPDFCropBox);
UIGraphicsBeginPDFPageWithInfo(templatePageBounds, nil);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawPDFPage(context, templatePage);
CGContextTranslateCTM(context, 0.0, templatePageBounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
}
CGPDFDocumentRelease(PDFDocument);
UIGraphicsEndPDFContext();
But I want any other easy way to convert PDFDocument to NSdataand save to a directory. Please, help.
source
share