3
我有两个UIView
需要转换为PDF并作为附件发送。我的代码与第一个UIView
重叠。 我想将此作为附件发送至电子邮件。如何从两个页面创建两个UIView的pdf
谢谢。
NSMutableData *pdfData=[NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData,aView.bounds, nil);
CGContextRef pdfContext=UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();
[aView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
UIGraphicsBeginPDFContextToData(pdfData, bView.bounds, nil);
CGContextRef pdfContext2=UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();
[bView.layer renderInContext:pdfContext2];
UIGraphicsEndPDFContext();
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
NSString *subject=[NSString stringWithFormat:@"Delivery Report-%@",[globUserID uppercaseString]];
[mailer setSubject:subject];
[mailer addAttachmentData:pdfData mimeType:@"pdf" fileName:@"DeliveryReport.pdf"];
[self presentModalViewController:mailer animated:YES];
非常感谢你的作品,任何提示,如果我想做第一页potrait第二页景观? – baste 2013-04-30 15:42:07
使用UIGraphicsBeginPDFPageWithInfo函数以不同尺寸开始新页面。 – rmaddy 2013-04-30 15:43:46
是否这样? 'NSMutableData * pdfData = [NSMutableData data]; CGRect bounds1 = aView.bounds; CGRect bounds2 = bView.bounds; UIGraphicsBeginPDFContextToData(pdfData,bounds1,nil); CGContextRef pdfContext = UIGraphicsGetCurrentContext(); UIGraphicsBeginPDFPage(); [aView.layer renderInContext:pdfContext]; UIGraphicsBeginPDFContextToData(pdfData,bounds2,nil); UIGraphicsBeginPDFPage(); [bView.layer renderInContext:pdfContext]; UIGraphicsEndPDFContext();' – baste 2013-04-30 15:52:25