Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在iOS上生成PDF时定位元素_Iphone_Ios_Ipad_Pdf - Fatal编程技术网

Iphone 在iOS上生成PDF时定位元素

Iphone 在iOS上生成PDF时定位元素,iphone,ios,ipad,pdf,Iphone,Ios,Ipad,Pdf,我正在我的ipad应用程序中生成一个PDF,我需要添加分页符,以便在渲染第二个页面之前移动元素。例如,在渲染第二页、第三页等之前,需要垂直调整我的长tableview 创建PDF非常简单,我已经完成了这一部分,第一页生成得非常完美,但是我尝试设置框架以移动下一页的tableview,但什么都没有发生: -(void) createPDF { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDi

我正在我的ipad应用程序中生成一个PDF,我需要添加分页符,以便在渲染第二个页面之前移动元素。例如,在渲染第二页、第三页等之前,需要垂直调整我的长tableview

创建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,因此它依赖于连接。

创建PDF的新页面实际有效吗?弄清楚这个图书馆真是太痛苦了。祝你好运。你所说的“将表格移动到任意位置进行测试,PDF中不会发生任何事情”是什么意思?由于您在PDF中呈现视图内容,视图在superview中的位置对呈现没有影响。@Jesse-是的,创建页面就像一个符咒@iPDFdev-这很有意义-那么我如何在PDF视图上下文中定位它呢?您需要在PDF上下文上应用平移变换,以将坐标系移动到所需的位置。