My goal is to combine two PDFs. One has 10 pages, and another has 6 pages, so the output should be 16 pages. My approach is to load both PDFs into two NSData stored in an NSMutableArray.
Here is my saving method:
NSMutableData *toSave = [NSMutableData data];
for(NSData *pdf in PDFArray){
[toSave appendData:pdf];
}
[toSave writeToFile:path atomically:YES];
However the output PDF only has the second part, which only contains 6 pages. So I don't know what did I miss. Can anyone give me some hints?
PDF is a file format which describes a single document. You cannot concatenate to PDF files to get the concatenated document.
But might achieve this with PDFKit:
This should look like:
You have to add either
#import <PDFKit/PDFKit.h>or@import PDFKit;to your source file, and you should addPDFKit.frameworkto the Linked Frameworks and Libraries of the build target in Xcode.