1
我在我的ipad应用程序中生成PDF,并且需要添加分页符,因此我还需要在呈现第二页之前移动元素。例如,我的长桌面将需要垂直调整,然后再渲染第二页,第三页等...在iOS上生成PDF时定位元素
创建PDF非常简单,我将该部分关闭,第一页完美生成,但是我尝试设置我的架动我的tableview下一个页面没有任何反应:
-(void) createPDF {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"tmp.pdf"];
CGContextRef pdfContext = [self createPDFContext:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) path:(CFStringRef)writableDBPath];
NSLog(@"PDF Context created");
CGContextBeginPage (pdfContext,nil); // 6
//turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0, self.view.bounds.size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);
//Draw view into PDF
self.view.frame=CGRectMake(0, 0,self.view.bounds.size.width, self.view.bounds.size.height);
[self.view.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);// 8
CGContextBeginPage (pdfContext,nil);
//turn PDF upsidedown
CGContextConcatCTM(pdfContext, transform);
// moving the table to an arbitrary position for testing, nothing happens in the PDF - view itself is updated
self.itemsTableView.frame = CGRectMake(100, 100, self.view.bounds.size.width, self.view.bounds.size.height);
[self.itemsTableView.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);// 8
CGContextRelease (pdfContext);
}
确实创造PDF的新页面实际工作?把这个图书馆弄出来真是太痛苦了。祝你好运。 –
“将表格移动到任意位置进行测试,PDF中没有任何反应”是什么意思?由于您在PDF中渲染视图内容,视图在超视图中的位置对渲染没有影响。 – iPDFdev
@Jesse - 是创建页面就像一个魅力。 @iPDFdev - 这很有道理 - 那么如何将它定位在PDF视图上下文中呢? – Slee