Open oskargargas opened 11 years ago
If you'd be interested in expanding MTPDF to create PDFs using UIImages I'd like to share this code as a starting point:
+ (MTPDF *)PDFWithImageArray: (NSArray /* <UIImage> */*)imageArray { NSMutableData *pdfData = [[NSMutableData alloc] init]; CGDataConsumerRef pdfConsumer = CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef) pdfData); CGContextRef pdfContext = CGPDFContextCreate(pdfConsumer, NULL, NULL); for (NSUInteger i = 0; i < imageArray.count; i++) { UIImage *image = imageArray[i]; CGFloat pageWidth = image.size.width; CGFloat pageHeight = image.size.height; CGRect pageRect = CGRectMake(0, 0, pageWidth, pageHeight); CGContextBeginPage(pdfContext,&pageRect); CGContextDrawImage(pdfContext, pageRect, image.CGImage); CGContextEndPage(pdfContext); } CGContextRelease(pdfContext); CGDataConsumerRelease(pdfConsumer); return [MTPDF PDFWithData:pdfData]; }
Thanks!
If you'd be interested in expanding MTPDF to create PDFs using UIImages I'd like to share this code as a starting point: