开发者

Selecting Text in PDF file (iphone)

I'am wo开发者_运维百科rking in a PDF reader for iphone and I want to learn how to Select a text in PDF, I was able to parse a PDF Document(using CGPDFContentStreamRef and CGPDFScannerRef), and to search for words in the pdf file, but i can't highlight the word in the PDF Document. So, how can I locate a word in the PDF View and How to select it?


You can try PDFKitten. There is some code in it.

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


Have you tried FastPDFKit?

https://github.com/mobfarm/FastPdfKit

It will highlight the search results, but won't let you select text by touching.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜