On this page
Guides
Split Pages
The steps to split pages are as follows:
- Create a new
CPDFDocument
object for each part to be split. - Add the portions of the target document that need to be split to the newly created
CPDFDocument
objects.
This example shows how to split pages:
swift
// Split out all pages in a loop
for i in 0..<(document?.pageCount ?? 0) {
let splitDocument = CPDFDocument()
let index = IndexSet(integer: IndexSet.Element(i))
splitDocument?.importPages(index, from: document, at: 0)
if let writeURL = URL(string: "writeFilePath") {
splitDocument?.write(to: writeURL)
}
}
objective-c
// Split out all pages in a loop
for (int i = 0; i < document.pageCount; i++) {
CPDFDocument *splitDocument = [[CPDFDocument alloc] init];
NSIndexSet *index = [[NSIndexSet alloc] initWithIndex:i];
[splitDocument importPages:index fromDocument:document atIndex:0];
[splitDocument writeToURL:[NSURL fileURLWithPath:@"writeFilePath"]];
}