Objective c 在Cocoa中组合PDF文件(快速枚举未实现)

Objective c 在Cocoa中组合PDF文件(快速枚举未实现),objective-c,cocoa,pdfkit,Objective C,Cocoa,Pdfkit,我想通过将每个PDF的页面附加到单个PDF中,将几个PDF合并为一个。此站点上的回答给出了以下代码(假设inputDocuments是PDFDocuments数组): PDFDocument *outputDocument = [[PDFDocument alloc] init]; NSUInteger pageIndex = 0; for (PDFDocument *inputDocument in inputDocuments) { for (PDFPage *page in inp

我想通过将每个PDF的页面附加到单个PDF中,将几个PDF合并为一个。此站点上的回答给出了以下代码(假设inputDocuments是PDFDocuments数组):

PDFDocument *outputDocument = [[PDFDocument alloc] init];
NSUInteger pageIndex = 0;
for (PDFDocument *inputDocument in inputDocuments) {
    for (PDFPage *page in inputDocument) {
        [outputDocument insertPage:page atIndex:pageIndex++];
    }
}
现在,我不知道PDFDocument类最初是否支持快速枚举,但现在似乎不支持。我尝试使用一系列for循环和一个单页PDFDocuments数组执行相同的操作,如下所示:

    PDFDocument *outputDocument = [[PDFDocument alloc] init];
    NSUInteger aPageCount=0;

    for (PDFConverter* aConverter in [self finishedPDFConverters])
    {
        [outputDocument insertPage:[[aConverter theDoc] pageAtIndex:0] atIndex:aPageCount];
        aPageCount++;
    }
但是我得到了错误

“2011-07-19 23:56:58.719 URLDownloader[37165:903]***WebKit丢弃了webView中未捕获的异常:didFinishLoadForFrame:delegate:**-[NSCFArray insertObject:atIndex:::]:索引(1)超出边界(1)”


添加第一个文档后,我得到的PDF只有一页。如何更正此错误?

错误与快速枚举无关


您试图在超出范围(>大于计数)的索引处插入页面。请尝试将
insertPage:atIndex:
替换为
addPage:

此错误与快速枚举无关


您试图在超出范围(>大于计数)的索引处插入页面。尝试用
addPage:
替换
insertPage:atIndex:
,在长时间的中断后返回此项目,我只需将PDF从最后一个循环到第一个,然后向后循环页面,并在索引0处插入每个页面,就解决了此问题。这很费解,但在之后返回此项目……

经过一段长时间的停顿,我修复了这个问题,只需将PDF从最后一页循环到第一页,然后将页面向后循环,并在索引0处插入每个页面。这很复杂,但很有效….

addPage:
似乎不存在。可能
insertPage:atIndex:
会在索引处的页面之后插入页面。
addPage:
似乎不存在。可能
insertPage:atIndex:
会在索引处的页面之后插入页面。我会尝试这样做。