Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone.I have created individual pages from different parts of my program and now nee
Here is a routine that I wrote to take a url for a pdf and append it to a context that you've already created (so that you can call it for multiple files and append them all):
- (void)appendPdfAtURL:(NSURL *)pdfURL toContext:(CGContextRef)pdfDestinationContext {
CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL((__bridge_retained CFURLRef)pdfURL);
if (pdfDoc) {
size_t numPages = CGPDFDocumentGetNumberOfPages(pdfDoc);
if (numPages > 0) {
// Loop through each page in the source file
for (size_t i = 1; i <= numPages; i++) {
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDoc, i);
if (pdfPage) {
// Get the page size
CGRect pdfCropBoxRect = CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox);
// Copy the page from the source file to the context
CGContextBeginPage(pdfDestinationContext, &pdfCropBoxRect);
CGContextDrawPDFPage(pdfDestinationContext, pdfPage);
}
}
}
// Close the source file
CGPDFDocumentRelease(pdfDoc);
}
}