【发布时间】:2011-05-21 09:32:22
【问题描述】:
我正在尝试创建当前视图的 PDF 文件。谁能告诉我一个教程链接,我可以在其中找到如何创建整个当前视图的 PDF 文件?
谢谢。
【问题讨论】:
标签: ipad pdf-generation
我正在尝试创建当前视图的 PDF 文件。谁能告诉我一个教程链接,我可以在其中找到如何创建整个当前视图的 PDF 文件?
谢谢。
【问题讨论】:
标签: ipad pdf-generation
先用这个函数将当前视图保存为图片:
- (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?
【讨论】: