1

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?

Daniel Lam
  • 11
  • 1
  • If your app just reads, searches and writes PDF documents, you may have a look at this: https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/QuartzFramework/Classes/PDFDocument_Class/Reference/Reference.html Should be much easier. – Daniel Sep 21 '12 at 09:57
  • It seems to be a Mac OS API. The iOS one doesn't have many api methods – Daniel Lam Sep 21 '12 at 10:26

0 Answers0