【发布时间】:2014-08-13 14:48:20
【问题描述】:
我有第一个视图firstView,还绘制了第二个视图secondView,并将其作为子视图添加到firstView。
我也有从firstView PDF 文件创建的方法:
-(void)createPDFfromUIView:(UIView*)firstView
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[firstView.layer drawInContext:pdfContext];
UIGraphicsEndPDFContext();
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"resolution.pdf"];
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
如何从这两个视图中绘制一个 PDF,因此 PDF 文件必须在一页包含 firstView 和 secondView
已添加
在 loadView 方法中的 ViewController 中
AWFirstView *firstView = [[AWFirstView alloc] init];
self.view = firstView;
self.secondView = [[AWSecondtView alloc] initWithFrame:CGRectMake(0, 50, 300., 300.)];
[self.secondView setBackgroundColor:[UIColor clearColor]];
self.createPDFButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.createPDFButton.frame =CGRectMake(0, 0, 88., 50.);
[self.createPDFButton setBackgroundColor:[UIColor whiteColor]];
[self.createPDFButton addTarget:self action:@selector(createPDF) forControlEvents:UIControlEventTouchUpInside];
[self updateView];
[self.view addSubview:self.drawWindow];
[self.view addSubview:self.createPDFButton];
在 updateView 中是这样的:
-(void)updateView
{
if(![self isViewLoaded])
return;
[[AWServices services].uiContext updateObjectInCurrentContext:&_resolution];
AWFirstView *view = (AWFirstView *)self.view;
view.post = _resolution.contact.officialPersonPost;
view.name = _resolution.contact.officialPersonFullname;
[view.superview setNeedsDisplay];
在
-(void)createPDF{
[self createPDFfromUIView:self.view];
}
【问题讨论】:
标签: ios objective-c pdf uiview