【问题标题】:e-signing my pdf file in ios limits my pdf content在 ios 中对我的 pdf 文件进行电子签名会限制我的 pdf 内容
【发布时间】:2013-11-06 14:01:54
【问题描述】:

我正在尝试签署我的多页 pdf 文件,我可以将 UIView 中绘制的签名提取到我的 pdf 文件中,但我面临的问题是,在签署 pdf 后,我只能查看文件的单页已签名,而不是我的 webview 中的其余页面。(例如;如果我的 pdf 文件的第 3 页已签名,我只能在我的 webview 中查看第 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文件中的其余页面。谁能帮我从这个问题中恢复过来。

【问题讨论】:

    标签: ios objective-c pdf digital-signature


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      • 2013-05-19
      • 2010-09-30
      • 1970-01-01
      相关资源
      最近更新 更多