Select text in a PDF file (iphone)

I work in a PDF reader for iphone and I want to learn how to select text in a PDF, I was able to parse a PDF document (using CGPDFContentStreamRef and CGPDFScannerRef) and search for words in a pdf file, but I cannot select that word in a PDF document. So, how can I find a word in a PDF view and how to choose it?

+3
source share
2 answers

You can try PDFKitten. It has a code.

- (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
source

Have you tried FastPDFKit?

https://github.com/mobfarm/FastPdfKit

It will display the search results, but will not allow you to select text by tapping.

0
source

Source: https://habr.com/ru/post/1763583/


All Articles