【发布时间】:2014-06-02 23:48:59
【问题描述】:
我想在现有的 pdf 上添加签名。我通过以下方式做到了这一点:
1) 在 UIView 上加载现有的 pdf,比如 mainView。
2) 在 mainView 上添加签名图片。
3) 调用以下函数
-(NSMutableData *)getPDFDatafromUIView
{
DebugLog(@"");
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, mainView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
mainView.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
return pdfData;
}
4) 这个函数会阻塞你的 UI 一段时间,所以在新线程上调用它
[NSThread detachNewThreadSelector:@selector(launchExportViewForExportDrawing) toTarget:self withObject:nil];
使用上述方法,我得到一个带有签名的 pdf 数据,其中也包含旧的 pdf 数据。
但是对于上述方法,我必须在 UIView 中显示 pdf。如果我想在不加载 UIView、不向用户显示 pdf 的情况下执行上述操作,我该怎么做?
我可以通过创建新的 pdf 页面在 pdf 上添加图像。如何在现有 pdf 上添加图像?
【问题讨论】:
-
我有pdf的NSData和签名的UIImage。从 ray 的教程 raywenderlich.com/6818/… 中,我可以在 PDF 上添加签名图像。但我不想创建新的 pdf。 “我想在现有 PDF 上添加签名”。
标签: ios objective-c ipad pdf pdf-generation