在ios中对我的pdf文件进行电子签名限制了我的pdf内容

时间:2013-11-06 14:01:54

标签: ios objective-c pdf digital-signature

我试图签署多页面的pdf文件,我可以将UIView中绘制的签名提取到我的pdf文件中,但我面临的问题是,在签署pdf之后,我只能查看文件的单页面签名,而不是我的网页浏览中的其余页面。(例如;如果我的pdf文件的第3页已签名,我只能在我的网页浏览中查看第3页。)

用于在我的pdf文件中提取电子签名的代码

- (void)viewWillAppear:(BOOL)animated
{
webView= [[UIWebView alloc] initWithFrame:CGRectMake(0,44, 320, 460)];
path1 = [[NSBundle mainBundle] pathForResource:@"typo_tips" ofType:@"pdf"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentDirectoryPath;
NSURL *targetURL;
documentDirectoryPath  = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"typo_tips.pdf"];
[fileManager copyItemAtPath:path1 toPath:documentDirectoryPath error:&error];

targetURL = [NSURL fileURLWithPath:documentDirectoryPath];

if (entered==1)//entered assigned 1, after save button clicked in UIView
{


    CFURLRef url;
    url = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:documentDirectoryPath]);
    CGPDFDocumentRef myDocument;
    myDocument = CGPDFDocumentCreateWithURL(url);

    CGContextRef pdfContext = CGPDFContextCreateWithURL(url, NULL, NULL); 
    CGPDFContextBeginPage(pdfContext, NULL);
    UIGraphicsPushContext(pdfContext);

    int totalPages = (int)CGPDFDocumentGetNumberOfPages(myDocument);
    NSLog(@"no. of pages in pdf is %d \n",totalPages);

   CGContextDrawPDFPage(UIGraphicsGetCurrentContext(),CGPDFDocumentGetPage(myDocument,page));
    //"page" is current pdf page to be signed, which can be fetched from user during runtime the pdf file is clicked.



    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];// image is the e-sign saved in doc. directory


    image = [[UIImage alloc] initWithContentsOfFile:filePath];
    CGRect imageRect = CGRectMake(50, 50, image.size.width, image.size.height);

    //  CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, image.size.height);
    //   CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
    CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image.CGImage);

    // Clean up
    UIGraphicsPopContext();
    CGPDFContextEndPage(pdfContext);
    CGPDFContextClose(pdfContext);

}

NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];

}

我可以猜出问题的原因,因为在图像与pdf文件合并之后,已签名的pdf的单页仍保留在文档目录中,因此我无法在pdf文件中显示其余页面。任何人都可以帮助我从这个问题中恢复过来。

1 个答案:

答案 0 :(得分:2)

您的代码未签署原始文件,它会创建单个页面的副本,然后对该页面进行签名。这就是你只看到一页的原因 您可以做的是将源文件复制到另一个文件(以与复制当前文件相同的方式复制每个页面),然后签署所需的页面。