在Quartz2d中创建一个包含多个页面的PDF文件

时间:2012-09-21 09:44:14

标签: objective-c ios pdf core-graphics cgpdfdocument

我目前正在开发iOS PDF阅读器。我能够在PDF文件的页面上绘制注释。但是,我无法导出包含多个页面的PDF文件。

我写了一个只能导出第一页的函数:

- (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);

}

如何修改此方法以导出多个页面?

0 个答案:

没有答案
相关问题