Merging PDF Files in Cocoa

问题:http://stackoverflow.com/questions/5610521/merging-pdf-files-in-cocoa

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 accomplish the merging. Should I have one PDFDocument and several PDFPage and then call insertPage on the PDFDocument ? Or is there a much simpler way? I dont want to alter the PDFs contetwise, I just want to merge them. Thanks a lot!

答案:

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 (PDFPage *page in inputDocument) {
        [outputDocument insertPage:page atIndex:pageIndex++];
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值