【问题标题】:How to generate PDF of current view - ipad如何生成当前视图的 PDF - ipad
【发布时间】:2011-05-21 09:32:22
【问题描述】:

我正在尝试创建当前视图的 PDF 文件。谁能告诉我一个教程链接,我可以在其中找到如何创建整个当前视图的 PDF 文件?

谢谢。

【问题讨论】:

    标签: ipad pdf-generation


    【解决方案1】:

    先用这个函数将当前视图保存为图片:

    - (void)saveScreenshot:(NSArray*)arguments withDict:(NSDictionary*)options 
    {
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGRect imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect));
    UIGraphicsBeginImageContext(imageRect.size);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextTranslateCTM(ctx, 0, 0);
    CGContextFillRect(ctx, imageRect);
    
    [webView.layer renderInContext:ctx];
    
    UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
    UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
    UIGraphicsEndImageContext();
    
    // alert to let us know success. remove this later.
    UIAlertView *alert= [[UIAlertView alloc] initWithTitle:nil message:@"Image Saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    }
    

    接下来按照 StackOverflow 问题中的说明将图像转换为 PDF:

    How can i create a PDF file programmatically in an iphone application?

    【讨论】:

      猜你喜欢
      • 2012-03-06
      • 2012-02-13
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      相关资源
      最近更新 更多