Skip to content

Instantly share code, notes, and snippets.

@jefferythomas
Created November 1, 2013 13:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefferythomas/7265536 to your computer and use it in GitHub Desktop.
Save jefferythomas/7265536 to your computer and use it in GitHub Desktop.
+combinePDFURLs:writeToURL: takes in an array of PDFs and combines them all together in the output URL.
+ (void)combinePDFURLs:(NSArray *)PDFURLs writeToURL:(NSURL *)URL
{
CGContextRef context = CGPDFContextCreateWithURL((__bridge CFURLRef)URL, NULL, NULL);
for (NSURL *PDFURL in PDFURLs) {
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)PDFURL);
size_t numberOfPages = CGPDFDocumentGetNumberOfPages(document);
for (size_t pageNumber = 1; pageNumber <= numberOfPages; ++pageNumber) {
CGPDFPageRef page = CGPDFDocumentGetPage(document, pageNumber);
CGRect mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
CGContextBeginPage(context, &mediaBox);
CGContextDrawPDFPage(context, page);
CGContextEndPage(context);
}
CGPDFDocumentRelease(document);
}
CGPDFContextClose(context);
CGContextRelease(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment