簡體   English   中英

如何在iPhone SDK中實現受密碼保護的PDF文件

[英]How to implement password protected PDF file in iPhone SDK

是否有人知道如何在iphone sdk中實現受密碼保護的PDF文件。 我的意思是我需要從我的應用程序創建一個密碼pdf文件。請幫助我。

任何人的幫助將不勝感激。

這是另一種可能更適合您的解決方案:

CGPDFContextCreate采用一個字典,您可以在其中傳遞密碼作為其中一個屬性。

有關CGPDFContxtCreate的詳細信息,請參閱Apple的參考文檔:

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

您可以在Apple的文檔中找到密碼設置信息:

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

我們可以使用以下方式提供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);

我有同樣的問題

我用一個小技巧解決了這個問題......也就是說,生成一個PDF並放入一個“密碼保護”的zip文件中

我使用zip庫ziparchive來保護

希望這有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM