我正在尝试签署我的多页 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文件中显示其余页面。任何人都可以帮助我从这个问题中恢复过来。