Ios 电子登录pdf文件,将多页pdf转换为具有相同内容的单个页面

Ios 电子登录pdf文件,将多页pdf转换为具有相同内容的单个页面,ios,pdf,integrate,electronic-signature,Ios,Pdf,Integrate,Electronic Signature,我试图通过将UIView中绘制的签名提取到我的pdf文件来对我的多页pdf文件进行签名,但我面临的问题是,在签署pdf文件后,签名与pdf文件集成,其中pdf文件中的所有页面都以pdf文件的形式显示在单个页面中。(例如,如果一个pdf文件中有8个页面,那么所有8个页面都将与签名一起显示为一个页面)。集成签名的pdf文件的输出如下所示 用于从文档目录获取图像并与pdf文件集成的代码为 - (void)viewWillAppear:(BOOL)animated { [webView reload]

我试图通过将UIView中绘制的签名提取到我的pdf文件来对我的多页pdf文件进行签名,但我面临的问题是,在签署pdf文件后,签名与pdf文件集成,其中pdf文件中的所有页面都以pdf文件的形式显示在单个页面中。(例如,如果一个pdf文件中有8个页面,那么所有8个页面都将与签名一起显示为一个页面)。集成签名的pdf文件的输出如下所示

用于从文档目录获取图像并与pdf文件集成的代码为

- (void)viewWillAppear:(BOOL)animated
{
[webView reload];

UIWebView *webView;
webView= [[UIWebView alloc] initWithFrame:CGRectMake(0,44, 320, 460)];

NSString *path1;
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];

NSLog(@"path1 value is %@ \n",path1);
NSLog(@"docu dir path is %@ \n",documentDirectoryPath);



if (entered==1)//"entered==1", after save button clicked in signviewcontroller 
{
targetURL = [NSURL fileURLWithPath:documentDirectoryPath];


}
else     targetURL = [NSURL fileURLWithPath:path1];


 if (entered==1)
{


CFURLRef url;
url = (CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:documentDirectoryPath]);
CGPDFDocumentRef myDocument;
myDocument = CGPDFDocumentCreateWithURL(url);

// Create PDF context
CGContextRef pdfContext = CGPDFContextCreateWithURL(url, NULL, NULL);     //(CFURLRef)outputURL
CGPDFContextBeginPage(pdfContext, NULL);
UIGraphicsPushContext(pdfContext);

int totalPages = (int)CGPDFDocumentGetNumberOfPages(myDocument);
NSLog(@"no. of pages in pdf is %d \n",totalPages);

for (int currentPage = 0; currentPage < totalPages; currentPage++)
{

CGContextDrawPDFPage(UIGraphicsGetCurrentContext(), CGPDFDocumentGetPage(myDocument, page));
//"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];
    CGRect imageRect = CGRectMake(50, 50, image.size.width, image.size.height);

    CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image.CGImage);
    }

}


// Clean up
UIGraphicsPopContext();
CGPDFContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);

}

NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
}
-(void)视图将显示:(BOOL)动画
{
[webView重新加载];
UIWebView*webView;
webView=[[UIWebView alloc]initWithFrame:CGRectMake(0,44320460)];
NSString*path1;
path1=[[NSBundle mainBundle]pathForResource:@“pdf”类型的“打字技巧”;
NSFileManager*fileManager=[NSFileManager defaultManager];
n错误*错误;
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,是);
NSString*documentDirectoryPath;
NSURL*目标URL;
documentDirectoryPath=[[paths objectAtIndex:0]stringByAppendingPathComponent:@“typo_tips.pdf”];
[fileManager copyItemAtPath:path1 toPath:documentDirectoryPath错误:&错误];
NSLog(@“路径1值为%@\n”,路径1);
NSLog(@“docu dir path为%@\n”,documentDirectoryPath);
如果(输入==1)/“输入==1”,则在signviewcontroller中单击保存按钮后
{
targetURL=[NSURL fileURLWithPath:documentDirectoryPath];
}
else targetURL=[NSURL fileURLWithPath:path1];
如果(输入==1)
{
cfurlRefURL;
url=(CFURLRef)CfBrigingRetain([NSURL fileURLWithPath:documentDirectoryPath]);
CGPDFDocumentRef myDocument;
myDocument=CGPDFDocumentCreateWithURL(url);
//创建PDF上下文
CGContextRef pdfContext=CGPDFContextCreateWithURL(url,NULL,NULL);//(CFURLRef)outputURL
CGPDFContextBeginPage(pdfContext,NULL);
UIGraphicsPushContext(pdfContext);
int totalPages=(int)CGPDFDocumentGetNumberOfPages(myDocument);
NSLog(@“pdf中的页数为%d\n”,总页数);
对于(int currentPage=0;currentPage

有谁能帮助我,如何单独显示pdf页面以及集成的电子签名。

您使用的是使用iOS内置pdf阅读类的webview来显示it Reader

否则,请尝试调整UIWebview上的缩放级别。不幸的是,UIWebview的选项有限,因为它只是一个web容器。

请尝试以下操作:

// Create PDF context
CGContextRef pdfContext = CGPDFContextCreateWithURL(url, NULL, NULL);     //(CFURLRef)outputURL

int totalPages = (int)CGPDFDocumentGetNumberOfPages(myDocument);
NSLog(@"no. of pages in pdf is %d \n",totalPages);

for (int currentPage = 0; currentPage < totalPages; currentPage++)
{
    CGPDFContextBeginPage(pdfContext, NULL);
    UIGraphicsPushContext(pdfContext);

    CGContextDrawPDFPage(UIGraphicsGetCurrentContext(), 
        CGPDFDocumentGetPage(myDocument, page));
    //"page" is current pdf page to be signed

    if (page == currentPage)
    {
        NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];

        image = [[UIImage alloc] initWithContentsOfFile:filePath];
        CGRect imageRect = CGRectMake(50, 50, image.size.width, image.size.height);

        CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image.CGImage);
    }

    // Clean up
    UIGraphicsPopContext();
    CGPDFContextEndPage(pdfContext);
}

CGPDFContextClose(pdfContext);

以及相应的清理代码。

我已经用输出图像更新了我的问题,请看一看并帮助我如何显示为多页pdf文件。实际上,缩放不是我的问题。
    CGPDFContextBeginPage(pdfContext, NULL);
    UIGraphicsPushContext(pdfContext);