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