【问题标题】:Selecting Text in PDF file (iphone)选择 PDF 文件中的文本 (iphone)
【发布时间】:2010-09-07 09:51:02
【问题描述】:

我正在为 iPhone 使用 PDF 阅读器,并且 我想学习如何选择 PDF 中的文本, 我能够解析 PDF 文档(使用 CGPDFContentStreamRef 和 CGPDFScannerRef),并在 pdf 文件中搜索单词,但我无法突出显示 PDF 文档中的单词。 那么,如何在 PDF 视图中找到一个单词以及如何选择它呢?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    你可以试试 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;
    }
    

    【讨论】:

    • 我正在尝试做同样的事情,如何使用此代码在触摸时突出显示?
    【解决方案2】:

    你试过 FastPDFKit 吗?

    https://github.com/mobfarm/FastPdfKit

    它会突出显示搜索结果,但不会让您通过触摸来选择文本。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 2017-08-08
    相关资源
    最近更新 更多