开发者

How to generate PDF of current view - ipad

I am trying to create a PDF file o开发者_如何学编程f current view. Can anyone please tell me about a tutorial link where I can find how to create PDF file of whole current view?

Thanks.


First save the current view as an image with this function:

- (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];
}

Next convert the image to PDF by following the directions in this StackOverflow question:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜