Skip to content

合并页面

以下是合并页面的步骤:

  1. 创建一个空白 PDF 文档。
  2. 打开包含要合并页面的 PDF 文档。
  3. 选中所有需要合并的页面,将其合并到同一个文档中。

以下是合并页面的示例代码:

objective-c
CPDFDocument *mergeDocument = [[CPDFDocument alloc] init];

CPDFDocument *document1 = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"filePath1"]];
CPDFDocument *document2 = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"filePath2"]];

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:1];
[mergeDocument importPages:indexSet fromDocument:document1 atIndex:mergeDocument.pageCount];//插入前两页
[mergeDocument importPages:indexSet fromDocument:document2 atIndex:mergeDocument.pageCount];