Merging PDF Files in Cocoa

后端 未结 1 1511
遥遥无期
遥遥无期 2020-12-14 05:09

I would like to concatenate several PDF files to form one single PDF. Now I\'ve come so far that I know, PDFKit is the proper way to go (I guess). But I am not sure, how to

相关标签:
1条回答
  • 2020-12-14 05:11

    As you indicated, you need one output PDFDocument object which will contain all pages of all input PDF files. To do so, you'll need to loop through all input files, create PDFDocument objects for each one and iterate over all pages to add them using insertPage to the output PDFDocument object.

    Assuming that inputDocuments is an NSArray of one ore more PDFDocument objects, you can use this snippet:

    PDFDocument *outputDocument = [[PDFDocument alloc] init];
    NSUInteger pageIndex = 0;
    for (PDFDocument *inputDocument in inputDocuments) {
        for (NSUInteger j = 0; j < [inputDocument pageCount]; j++) {
            PDFPage *page = [inputDocument pageAtIndex:j];
            [outputDocument insertPage:page atIndex:pageIndex++];
        }
    }
    
    0 讨论(0)
提交回复
热议问题