我正在编写一个 iPad 应用程序,它使用带有页面控制的滚动视图。
我需要将所有页面创建为 1 个 PDF 文件。
到目前为止,我认为我应该循环遍历所有子视图(页面)并为每个子视图(使用 CGPDFContext)创建 PDF 文件。但我确实需要将所有文件合并为 1 个 PDF 文档。你能帮我这样做吗?
或者,如果您有更好的方法从该滚动视图创建包含多个页面的 PDF 文档,那就更好了!
请帮忙。我到处搜索了一下,发现Mac OS有一些使用PDFDocument、insertPage功能的东西。我在iOS上找不到类似的方法?
创建多部分 PDF:
-(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(NSString *) path
{
CGContextRef myOutContext = NULL;
NSURL * url;
url = [NSURL fileURLWithPath:path];
if (url != NULL) {
myOutContext = CGPDFContextCreateWithURL (url,// 2
&inMediaBox,
NULL);
}
return myOutContext;// 4
}
-(void)createPdfFromScrollview:(UIScrollView *)scrollview
{
CGContextRef pdfContext = [self createPDFContext:CGRectMake(0, 0, WIDTH, HEIGHT) path:outputFilePath];
for(UIView * view in scrollview.subviews)
{
CGContextBeginPage (pdfContext,nil);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0, HEIGHT);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);
//Draw view into PDF
[view.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);
}
CGContextRelease (pdfContext);
}
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)