iPad App:将PDF文件合并到1个PDF文档中/创建多页scrollview的PDF文档 [英] iPad App: Merge PDF files into 1 PDF document / Create PDF Document of multi-page scrollview

查看:805
本文介绍了iPad App:将PDF文件合并到1个PDF文档中/创建多页scrollview的PDF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个iPad应用程序,该应用程序使用带有页面控件的scrollview. 我需要将所有页面的PDF创建为1个PDF文件. 到目前为止,我认为应该遍历所有子视图(页面)并为每个子视图创建PDF文件(使用CGPDFContext).但是我确实需要将所有文件合并为1个PDF文档.你能帮我吗?

I am writing an iPad application which uses a scrollview with page control. I need to create a PDF of all the pages as 1 PDF file. So far, I figured that I should loop through all the sub-views (pages) and create PDF files for each (using CGPDFContext). BUT I do need to combine all the files into 1 PDF document. Can you help me to do so??

或者,如果您有更好的方法可以从此滚动视图中创建具有多个页面的PDF文档,那就更好了!

OR if you have a better way to create a PDF document with multiple pages from this scrollview, that would even be better!!

请帮助.我到处搜索,发现Mac OS使用PDFDocument,insertPage函数具有某些功能.我找不到适用于iOS的类似方法?

Please help. I've searched everywhere and saw that Mac OS has something using PDFDocument, insertPage function. I can't find a similar method for 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);
}

希望这会有所帮助.

这篇关于iPad App:将PDF文件合并到1个PDF文档中/创建多页scrollview的PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆