0
votes

In one of my iPad application I have created PDF report and show it in web view and user can email that report to customer. Following code I have used for creating the report.

NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"owner", kCGPDFContextOwnerPassword, @"user", kCGPDFContextUserPassword, kCFBooleanFalse, kCGPDFContextAllowsCopying, kCFBooleanFalse, kCGPDFContextAllowsPrinting,  nil];
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, dictionary);

Password protection is working fine for me.

But our requirement is, when user open that PDF file in web view in the application then It should not ask for Password. It will only ask for the password when user emailed that PDF file to customer and that customer tried to view it.

So I want to know whether there is any option so that we can open the PDF file by providing password programmatically inside the application when user view it in web view.

Thanks in Advance!!

3

3 Answers

0
votes

EDIT : You cannot open password protected PDF in UIWebView unless you unlock it.

Solution is need to first unlock use CGPDFDocumentUnlockWithPassword :

 CGPDFDocumentUnlockWithPassword(doc, pass).

You could then generate an unlocked version as NSData in memory and load that into the web view (not password protected at this point).

0
votes

Finally I have resolve the issue and created own pdf viewer using scroll view and views.

I have first unlocked the PDF view and then shown that pdf view using the reference of below url:

http://www.cocoanetics.com/2010/06/rendering-pdf-is-easier-than-you-thought/

Then assigned the zoom in/out to scroll view. Its working fine for me.

0
votes

You can make a NSData object out of the CFURL of which you create the CGPDFDocumentRef if that's what you want:

let url = yourCFURL as NSURL
let data = NSData(contentsOfUrl: url)