1

それぞれのページを 1 つの PDF に追加して、複数の PDF を 1 つに結合したいと考えています。このサイトの同じ質問に対する回答は、次のコードを提供しました (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 クラスがもともと高速列挙をサポートしていたかどうかはわかりませんが、現在はサポートされていないようです。次のように、単一ページの PDFDocuments の配列を使用して一連の for ループを使用して、同じことを試みました。

    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 discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSRangeException> *** -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1)"

最初のドキュメントが追加された後、1 ページしかない PDF になります。どうすればこれを修正できますか?

4

2 に答える 2

1

エラーは高速列挙に関するものではありません。

範囲外 (> カウント) のインデックスにページを挿入しようとしました。で置き換えinsertPage:atIndex:てみてくださいaddPage:

于 2011-07-20T05:25:36.380 に答える
0

Returning to this project after a long hiatus, I fixed the problem simply by looping through the PDFs from the last to the first, then looping through the pages backwards and inserting each at index 0. Convoluted, but it works....

于 2011-12-19T23:27:36.753 に答える