[英]How to create a pdf from two UIViews with 2 pages
I have two UIView
s that needs to be converted to a PDF and send as an attachment. 我有两个UIView
需要转换为PDF并作为附件发送。 My code below overlaps the first UIView
. 我的代码重叠了第一个UIView
。 I would like to send this as an attachment to an email. 我想将此作为电子邮件的附件发送。
Thank you. 谢谢。
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];
Don't create a second context. 不要创建第二个上下文。
NSMutableData *pdfData=[NSMutableData data];
CGRect bounds = CGRectMake(0, 0, 612, 792); // letter sized paper, adjust as needed
UIGraphicsBeginPDFContextToData(pdfData, bounds, nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();
[aView.layer renderInContext:pdfContext];
UIGraphicsBeginPDFPage();
[bView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.