2013-07-10 2 views
1

보기에서 PDF 파일을 만든 다음 이메일로 보낼 수있는 앱이 있습니다. PDF 파일을 생성하는 데 사용하는 코드는 다음과 같습니다.비밀번호로 PDF 보호

- (void)createPDFfromUIView:(UIView*)view saveToDocumentsWithFileName:(NSString*)aFilename 
{ 
    // Creates a mutable data object for updating with binary data, like a byte array 
    NSMutableData *pdfData = [NSMutableData data]; 

    // Points the pdf converter to the mutable data object and to the UIView to be converted 
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); 
    UIGraphicsBeginPDFPage(); 

    CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 

    [aView.layer renderInContext:pdfContext]; // this line 

    // remove PDF rendering context 
    UIGraphicsEndPDFContext(); 

    // Retrieves the document directories from the iOS device 
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); 

    NSString* documentDirectory = [documentDirectories objectAtIndex:0]; 
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"cherry"]; 

    [pdfData writeToFile:documentDirectoryFilename atomically:YES]; 
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename); 
} 

완벽하게 작동합니다. 그러나 PDF 암호를 보호 할 수있는 기능을 구현하고 싶습니다. 따라서 PDF를 전자 메일로 보내는 경우 보려면 PDF를 보려면 암호를 입력해야합니다. 나는 이것을하는 방법에 대해 완전히 확신 할 수 없다. 나는 안으로 추가했다 :

NSMutableDictionary *myDictionary = CFBridgingRelease(CFDictionaryCreateMutable(NULL, 0, 
              &kCFTypeDictionaryKeyCallBacks, 
              &kCFTypeDictionaryValueCallBacks)); 
    CFDictionarySetValue((__bridge CFMutableDictionaryRef)(myDictionary), kCGPDFContextUserPassword, CFSTR("userpassword")); 
    CFDictionarySetValue((__bridge CFMutableDictionaryRef)(myDictionary), kCGPDFContextOwnerPassword, CFSTR("ownerpassword")); 

나는 적당한 선상에있는 것처럼 느낀다, 그러나 나는 여기에서 무엇을해야하는지 완전히 모른다. PDF를 보호하는 암호 코드에 관한 문서를 읽었습니다. https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF101 하지만 여전히 내 머리 위로 간다.

암호를 보호하기 위해이 코드를 수정해야하는 사람이 누구인지 알고 있다면 정말 좋을 것입니다. myDictionary와 마지막 매개 변수를 대체하여

UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); 

:

답변

3

당신은에 대한 호출을 업데이트해야합니다.

UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, myDictionary); 
+0

대단히 감사합니다. rmaddy! – John

관련 문제