在pdf文件中集成电子签名-ios,以坐标发布
我试图通过从文档目录中获取签名并将其放置在pdf文件的固定位置(例如(50,50))来将签名集成到pdf文件中。但是当试图通过用户的点击位置来整合签名时,它没有被放置在适当的位置。 在pdf文件的多个位置添加的签名的屏幕截图如下所示 这里我点击了pdf文件的每个位置,但签名只添加在pdf文件的中心在pdf文件中集成电子签名-ios,以坐标发布,ios,pdf,digital-signature,integrate,Ios,Pdf,Digital Signature,Integrate,我试图通过从文档目录中获取签名并将其放置在pdf文件的固定位置(例如(50,50))来将签名集成到pdf文件中。但是当试图通过用户的点击位置来整合签名时,它没有被放置在适当的位置。 在pdf文件的多个位置添加的签名的屏幕截图如下所示 这里我点击了pdf文件的每个位置,但签名只添加在pdf文件的中心 CGPoint tapLocation = [gesture locationInView: self.view]; NSLog(@"tapped location is %@ \n",NSStri
CGPoint tapLocation = [gesture locationInView: self.view];
NSLog(@"tapped location is %@ \n",NSStringFromCGPoint(tapLocation));
NSInteger x,y;
x=tapLocation.x;
y=tapLocation.y;
CGRect imageRect = CGRectMake(x,568-y, image.size.width, image.size.height);
在抽头位置添加签名在这里是不可能的,但我尝试了translatecm和ScaleCTM,这也产生了相同的结果。为了在适当的攻丝位置获得签名,还需要做些什么
更新的问题
webView= [[UIWebView alloc] initWithFrame:CGRectMake(0, 60, 320, 568)];
- (void) singleTap:(UITapGestureRecognizer*)gesture
{
// handle event
NSLog(@"single tap is handled");
CGPoint tapLocation = [gesture locationInView:webView];
NSLog(@"tapped location is %@ \n",NSStringFromCGPoint(tapLocation));
NSInteger x,y;
x=tapLocation.x;
y=tapLocation.y;
NSLog(@"location:x %d\n",x);
NSLog(@"location:y %d\n",y);
CGPoint pointInView1 = [webView convertPoint:tapLocation toView:self.window];//change of +80 in y
NSLog(@"pointinview is %@ \n",NSStringFromCGPoint(pointInView1));
xy = pointInView1.x;
yz = pointInView1.y;
if (entered==1)
{
// CFStringRef path;
CFURLRef url;
url = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:documentDirectoryPath]);
CGPDFDocumentRef myDocument;
myDocument = CGPDFDocumentCreateWithURL((CFURLRef)url);
// Create PDF context
CGContextRef pdfContext = CGPDFContextCreateWithURL(url, NULL, NULL);
int totalPages = (int)CGPDFDocumentGetNumberOfPages(myDocument);
NSLog(@"no. of pages in pdf is %d \n",totalPages);
//alter each page of a pdf
for (int currentPage = 1; currentPage <= totalPages; currentPage++)
{
CGPDFContextBeginPage(pdfContext, NULL);
UIGraphicsPushContext(pdfContext);
CGContextDrawPDFPage(UIGraphicsGetCurrentContext(), CGPDFDocumentGetPage(myDocument, currentPage)); //"page" is current pdf page to be signed
if (page == currentPage)
{
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];// "image.png" is the saved user's signature in document directory
image = [[UIImage alloc] initWithContentsOfFile:filePath];
// Translate the origin of the coordinate system at the
// bottom left corner of the page rectangle.
// CGContextTranslateCTM(pdfContext, 0,1);
// Reverse the Y axis to grow from bottom to top.
// CGContextScaleCTM(pdfContext, 1, 1);
CGRect imageRect = CGRectMake(x,568-y, image.size.width, image.size.height);
CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image.CGImage);
}
// Clean up
UIGraphicsPopContext();
CGPDFContextEndPage(pdfContext);
}
CGPDFContextClose(pdfContext);
// _sign_label.text = @"";
}
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
}
webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,60320568)];
-(无效)单点击:(UITapgestureRecognitor*)手势
{
//处理事件
NSLog(“处理单抽头”);
CGPoint TAPPLOCATION=[手势位置查看:网络视图];
NSLog(@“抽头位置为%@\n”,NSStringFromCGPoint(抽头位置));
NSInteger x,y;
x=tapLocation.x;
y=tapLocation.y;
NSLog(@“位置:x%d\n”,x);
NSLog(@“位置:y%d\n”,y);
CGPoint pointInView1=[webView convertPoint:tapLocation-toView:self.window];//y中+80的更改
NSLog(@“pointinview是%@\n”,NSStringFromCGPoint(pointInView1));
xy=点INVIEW1.x;
yz=点inview1.y;
如果(输入==1)
{
//CFStringRef路径;
cfurlRefURL;
url=(CFURLRef)CfBrigingRetain([NSURL fileURLWithPath:documentDirectoryPath]);
CGPDFDocumentRef myDocument;
myDocument=CGPDFDocumentCreateWithURL((CFURLRef)url);
//创建PDF上下文
CGContextRef pdfContext=CGPDFContextCreateWithURL(url,NULL,NULL);
int totalPages=(int)CGPDFDocumentGetNumberOfPages(myDocument);
NSLog(@“pdf中的页数为%d\n”,总页数);
//更改pdf的每一页
对于(int currentPage=1;currentPage)您能提供详细的pdf代码吗?@PradhyumanChavda,是的,我已经更新了问题的详细代码,请检查。@PradhyumanChavda,您能从更新的pdf代码中得到任何想法吗?