I used the following methods to create a PDF file from a UIView. All of them create PDF, but lose quality:
Method 1:
@implementation UIView(PDFWritingAdditions) - (void)renderInPDFFile:(NSString*)path { CGRect mediaBox = self.bounds; CGContextRef ctx = CGPDFContextCreateWithURL((__bridge_retained CFURLRef)[NSURL fileURLWithPath:path], &mediaBox, NULL); CGPDFPageRef page; CGContextDrawPDFPage(ctx, page); CGPDFContextBeginPage(ctx, NULL);
Method 2:
- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename {
I think that maybe I am missing some settings for the pdf context, not sure. I also create a png image from UIView with the following method, which is exactly the same quality:
- (UIImage *)imageFromView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
Can anyone see what I'm doing wrong? Thanks.
ios iphone pdf ipad render
iEamin
source share