3

I'am working 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?

user441298
  • 31
  • 1
  • 3

2 Answers2

2

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;
}
LPL
  • 16,827
  • 6
  • 51
  • 95
nikodev
  • 21
  • 2
0

Have you tried FastPDFKit?

https://github.com/mobfarm/FastPdfKit

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

topace
  • 1,791
  • 3
  • 17
  • 23
  • @user441298: Did you try this? – topace Mar 03 '11 at 07:22
  • can you please answer this http://stackoverflow.com/questions/5335799/is-there-any-framework-to-highlight-text-on-pdf-file-after-rendering-in-iphone – ajay Mar 21 '11 at 10:47