2010-04-30 107 views

回答

0

我有同樣的問題

我已經解決了使用小竅門......也就是說,生成PDF並投入了「密碼保護」的壓縮文件,我使用的問題

拉鍊庫ziparchive,使保護

希望這有助於

+0

當您在PC中提取zipfile(由zip庫ziparchive創建)時,發生了什麼事情要求輸入密碼? – 2013-08-14 10:07:39

+0

通常是...取決於ZIP客戶端應用程序。在我的情況下,我使用應用程序本身來擴展存檔 – bsorrentino 2013-08-16 09:18:27

4

這裏是另一種解決方案,可能是你的目的更好:

CGPDFContextCreate需要一個可以將密碼作爲屬性之一傳遞的字典。

爲CGPDFContxtCreate你會在找到蘋果的參考文件的細節:

http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/c/func/CGPDFContextCreate

你會在蘋果的文檔在這裏找到密碼設置信息:

http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPDFContext/Reference/reference.html#//apple_ref/doc/constant_group/Auxiliary_Dictionary_Keys

1

我們可以通過以下方式提供PDF文件的密碼:

 NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"owner", kCGPDFContextOwnerPassword, @"user", kCGPDFContextUserPassword, kCFBooleanFalse, kCGPDFContextAllowsCopying, kCFBooleanFalse, kCGPDFContextAllowsPrinting, nil]; 
     NSFileManager *fileManager = [NSFileManager defaultManager]; 
     NSString *fileName = [NSString stringWithFormat:@"%@/Documents/samplePDF.pdf", NSHomeDirectory()]; 
     if (![fileManager fileExistsAtPath:fileName]) { 
      [fileManager createFileAtPath:fileName contents:nil attributes:nil]; 
     } 

     // Create the PDF context using the default page size of 612 x 792. 
     UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, dictionary);