在pdf文件中集成电子签名 - ios,在坐标中发布

时间:2013-11-27 08:47:02

标签: ios pdf digital-signature integrate

我试图通过从文档目录中获取签名来将签名集成到pdf文件中,并将其放在固定位置的pdf文件中(例如50,50)。但是当试图通过用户的敲击位置整合签名时,它不会被放置在适当的位置。 我在pdf文件的多个位置添加的签名的屏幕截图如下所示。

Screenshot

在这里,我点击了pdf文件的每个位置,但签名仅添加到pdf文件的中心,

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);

此处无法在分接位置添加签名,但我尝试了translateCTM和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];

}

0 个答案:

没有答案