2011-06-27 23 views
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); 
    } 
+0

确实创造PDF的新页面实际工作?把这个图书馆弄出来真是太痛苦了。祝你好运。 –

+0

“将表格移动到任意位置进行测试,PDF中没有任何反应”是什么意思?由于您在PDF中渲染视图内容,视图在超视图中的位置对渲染没有影响。 – iPDFdev

+0

@Jesse - 是创建页面就像一个魅力。 @iPDFdev - 这很有道理 - 那么如何将它定位在PDF视图上下文中呢? – Slee

回答

0

如果你的应用程序使用云服务来创建PDF的选项,看看Docmosis。 PDF基于文档模板,因此您可以控制分页符等,而无需在代码中进行计算。您的应用程序必须发送请求和数据来填充文档并发送PDF,因此它依赖于连接。