公司做金融類的業(yè)務(wù),需要用到一個關(guān)于電子簽章問題,在電腦上,用正常的PDF閱讀器.
服務(wù)器會使用使用一些第三方的電子簽章,最后在app上顯示.
先看看對比
正常的:
正常樣式.png
非正常的:
非正常的.png
一些文章中介紹
iOS展示pdf簽名時遇到的問題及解決辦法
iOS下pdf無法顯示簽名的問題
如果直接用原生的UIWebView去加載這些添加了電子簽章的PDF之后會無法顯示.
stackoverflow上的解釋是:
The signature you saw in the PDF file is the appearance of the signature field widget. The field widget is a specific PDF annotation.
The problem with the default PDF rendering engine in iOS (used by UIDocumentInteractionController, QuickLook framework, etc) is that it does not display the annotations on the PDF page, it displays only the main page content.
The only solution is to use a 3rd party PDF rendering engine, such as MuPDF, Foxit, PDFTron, etc.
中文意思:
(谷歌翻譯)您在PDF文件中看到的簽名是簽名字段小部件的外觀弊琴。 字段小部件是特定的PDF注釋幻梯。
iOS中的默認(rèn)PDF渲染引擎(由UIDocumentInteractionController澈蟆,QuickLook框架等使用)的問題是它不會在PDF頁面上顯示注釋,它只顯示主頁面內(nèi)容散怖。
唯一的解決方案是使用第三方PDF渲染引擎急但,如MuPDF恕稠,F(xiàn)oxit佑附,PDFTron等樊诺。
嘗試了用MuPDF,普遍都在指導(dǎo)使用這個,但是個人覺得缺點(diǎn)太多.
- 集成之后項(xiàng)目整個項(xiàng)目瞬間大了400M,app打包出來也打了一倍.
- 需要設(shè)置項(xiàng)目配置,調(diào)到你懷疑人生.
- 晰度太差,這個是最主要的.
找到一個不錯的解決辦法:
GitHub上找到別人寫的不錯的代碼,里面有4中加載PDF的方式 : OpenPDFDemo
我是使用了QuickLook.framework解決了我的問題
簡答粗暴,不需要集成. 預(yù)先準(zhǔn)備一個加了電子簽章的pdf,就叫"a.pdf"吧
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 100, 44);
btn.center = self.view.center;
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"btnClick" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor redColor]];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
}
- (void)btnClick {
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
[self presentViewController:previewController animated:YES completion:nil];
}
#pragma - mark QLPreviewControllerDataSource
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"pdf"];
return [NSURL fileURLWithPath:path];
}
嘗試結(jié)果 :