Created
November 1, 2013 13:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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