I want to combine several PDFs into one by appending the pages of each to a single PDF. An answer to an identical question on this site gave the following code (assuming inputDocuments is an array of PDFDocuments:
PDFDocument *outputDocument = [[PDFDocument alloc] init];
NSUInteger pageIndex = 0;
for (PDFDocument *inputDocument in inputDocuments) {
for (PDFPage *page in inputDocument) {
[outputDocument insertPage:page atIndex:pageIndex++];
}
}
Now, I don't know if the PDFDocument class originally supported fast enumeration, but it doesn't appear to now. I tried doing the same thing using a series of for-loops with an array of single-page PDFDocuments with the following:
PDFDocument *outputDocument = [[PDFDocument alloc] init];
NSUInteger aPageCount=0;
for (PDFConverter* aConverter in [self finishedPDFConverters])
{
[outputDocument insertPage:[[aConverter theDoc] pageAtIndex:0] atIndex:aPageCount];
aPageCount++;
}
However I get the error
"2011-07-19 23:56:58.719 URLDownloader[37165:903] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSRangeException> *** -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1)"
after the first Document has been added, so I end up with a PDF with only 1 page. How can I rectify this?