【发布时间】:2010-09-07 09:51:02
【问题描述】:
我正在为 iPhone 使用 PDF 阅读器,并且 我想学习如何选择 PDF 中的文本, 我能够解析 PDF 文档(使用 CGPDFContentStreamRef 和 CGPDFScannerRef),并在 pdf 文件中搜索单词,但我无法突出显示 PDF 文档中的单词。 那么,如何在 PDF 视图中找到一个单词以及如何选择它呢?
【问题讨论】:
标签: iphone
我正在为 iPhone 使用 PDF 阅读器,并且 我想学习如何选择 PDF 中的文本, 我能够解析 PDF 文档(使用 CGPDFContentStreamRef 和 CGPDFScannerRef),并在 pdf 文件中搜索单词,但我无法突出显示 PDF 文档中的单词。 那么,如何在 PDF 视图中找到一个单词以及如何选择它呢?
【问题讨论】:
标签: iphone
你可以试试 PDFKitten。里面有一些代码。
- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
CGPDFDocumentRef doc = CGPDFDocumentRetain(self.document);
CGPDFPageRef page = CGPDFDocumentGetPage(doc, 1);
// Transform the CTM compensating for flipped coordinate system
CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
// Draw PDF (scaled to fit)
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, layer.bounds, 0, YES));
CGContextDrawPDFPage(ctx, page);
for (Selection *s in self.selections)
{
CGContextSaveGState(ctx);
CGContextConcatCTM(ctx, [s transform]);
CGContextSetFillColorWithColor(ctx, [[UIColor yellowColor] CGColor]);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextFillRect(ctx, [s frame]);
CGContextRestoreGState(ctx);
}
CGPDFDocumentRelease(doc); doc = nil;
}
【讨论】:
【讨论】: