Is there any way to get the content of a UIWebView
and convert it to a PDF or PNG file? I\'d like to get similar output to that available on the Mac by selectin
You can use the following category on UIView to create a PDF file:
#import
@implementation UIView(PDFWritingAdditions)
- (void)renderInPDFFile:(NSString*)path
{
CGRect mediaBox = self.bounds;
CGContextRef ctx = CGPDFContextCreateWithURL((CFURLRef)[NSURL fileURLWithPath:path], &mediaBox, NULL);
CGPDFContextBeginPage(ctx, NULL);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -mediaBox.size.height);
[self.layer renderInContext:ctx];
CGPDFContextEndPage(ctx);
CFRelease(ctx);
}
@end
Bad news: UIWebView does not create nice shapes and text in the PDF, but renders itself as an image into the PDF.