me trató de usar la información dada aquípdf protegido contraseña en Objective-C
pero es muy vaga ...
También he intentado usar este código usando UIKit ... se crea el archivo .. pero es de 0 kb .. no se puede escribir cualquier dato ..
BOOL allowCopy=YES;
BOOL allowPrint=YES;
//NSString *[email protected]"test";
CGContextRef pdfContext; //our pdfContext
CFStringRef path;
CFURLRef url;
CGRect pageRect = CGRectMake(0, 0,500, 500);
NSString *[email protected]"Test.pdf";
// CFStringRef passwordString = (__bridge_retained CFStringRef)password;
const char *filename = [fileName UTF8String];
// Create a CFString from the filename we provide to this method when we call it
path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
// Create a CFURL using the CFString we just defined
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CFMutableDictionaryRef myDictionary = NULL;
// This dictionary contains extra options mostly for 'signing' the PDF
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("user"));
CFDictionarySetValue(myDictionary, kCGPDFContextUserPassword, CFSTR("user"));
if (!allowCopy)
CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
//kCGPDFContextAllowsCopying is set to TRUE by default
if (!allowPrint)
CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanFalse);
//kCGPDFContextAllowsPrinting is set to TRUE by default
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createFileAtPath:dataPath contents:nil attributes:nil];
// CGRect papersize= CGRectMake(0, 0, 400, 400);
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
// Cleanup our mess
CFRelease(myDictionary);
CFRelease(url);
//Now, this is a tricky part. We make use of a do - while loop in order to create as many pages as needed
CGContextBeginPage (pdfContext, &pageRect); //begins a new PDF page
//create layout for our page
CGRect bounds = CGRectMake(0, 0,500,500);
UIGraphicsPushContext(pdfContext); //pushing the context, as explained at the beginning of this post
CGContextSaveGState(pdfContext);
CGContextTranslateCTM(pdfContext, 0, bounds.origin.y);
CGContextScaleCTM(pdfContext, 1, -1);
CGContextTranslateCTM(pdfContext, 0, -(bounds.origin.y + bounds.size.height));
//[@"HELLO" drawInRect:CGRectMake(10,15,10,30) withFont:[UIFont fontWithName:@"Helvetica-Bold" size:40]];
//THIS IS THE NASTY PART
CGContextRestoreGState(pdfContext);
UIGraphicsPopContext();
CGContextEndPage (pdfContext); //ends the current page
// We are done with our context now, so we release it
CGContextRelease (pdfContext);
CFRelease(path);
// Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
si alguien puede ayudar .. gracias ..