我想替换 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;
}
(它在指定页面中添加图像,我可能需要绘制路径或文本)。
我在这里面临的问题是,修改后的文件只有更改后的页面。为了避免它,我画了所有的页面。但是正如预期的那样,大文件的性能是如此糟糕。有什么方法可以只修改特定页面吗?还有其他更好的方法吗?请帮忙。