在目标C中绘制PDF文件

时间:2012-01-06 10:39:53

标签: ios pdf

我想替换pdf页面的内容。我通过以下代码完成了这项工作,

-(void)modifyPdf:(NSString *)pdfPath atPage:(int)_page
{
NSURL* url = [NSURL fileURLWithPath:pdfPath];

CGPDFDocumentRef document = CGPDFDocumentCreateWithURL ((CFURLRef) url);

CGRect paperSize = CGPDFPageGetBoxRect(CGPDFDocumentGetPage (document, 1), kCGPDFMediaBox);
UIGraphicsBeginPDFContextToFile(pdfPath, paperSize, nil);

UIGraphicsBeginPDFPageWithInfo(paperSize, nil);

CGContextRef currentContext = UIGraphicsGetCurrentContext();

CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
CGContextScaleCTM(currentContext, 1.0, -1.0); 

CGPDFPageRef page = CGPDFDocumentGetPage (document, _page);

CGContextDrawPDFPage (currentContext, page);

CGContextDrawImage(currentContext, CGRectMake(0, 0, 100, 100), [UIImage imageNamed:@"0_0_0.png"].CGImage);


UIGraphicsEndPDFContext();

CGPDFDocumentRelease(document);
document = nil;   
}

(它在指定页面中添加图像,我可能需要绘制路径或文本)。

我遇到的问题是,修改后的文件只有更改过的页面。为了避免它,我已经绘制了所有页面。但是对于大文件来说,性能如此可怕。有没有办法只修改一个特定的页面?还有其他更好的方法吗?请帮忙。

0 个答案:

没有答案