I am currently working on an iOS PDF reader. I am able to draw annotations on pages of a PDF file. However, I cannot export such a PDF file with more than one page.
I wrote a function which can export only the first page:
- (void)createPDFFileFromPath:(NSString*)oldPath to:(NSString*)newPath{
CFStringRef path = CFStringCreateWithCString (NULL, [oldPath cStringUsingEncoding:NSUTF8StringEncoding],kCFStringEncodingUTF8);
CFURLRef url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL(url);
int pageCount = CGPDFDocumentGetNumberOfPages(document);
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(document, 1);
CGRect frame = CGPDFPageGetBoxRect(pdfPage, kCGPDFMediaBox);
UIGraphicsBeginPDFContextToFile(newPath, frame, nil);
UIGraphicsBeginPDFPageWithInfo(frame, nil);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context,1.0,1.0,1.0,1.0);
CGContextFillRect(context, frame);
//Draw other graphics e.g. annnoation into context here.
// Flip the context so that the PDF page is rendered right side up.
CGContextTranslateCTM(context, 0.0, frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawPDFPage(context, pdfPage);
UIGraphicsEndPDFContext();
CGPDFDocumentRelease(document);
}
How can I modify this method in order to export more than one page?