NSStringテキストをPDFに描画する必要があるプロジェクトに取り組んでいます。PDF形式のテキストを単色で描くことができます。特定の文字列をPDFで検索し、別の色でマークできる検索方法をPDFに実装したいと思います。
以下は、PDFで単色のテキストを描画するために使用しているコードです。
- (void) drawText
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 1.0, 1.0);
NSString *textToDraw = pdfTextView.text;
UIFont *font = [UIFont systemFontOfSize:14.0];
CGSize stringSize = [textToDraw sizeWithFont:font
constrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset-2*kMarginInset, pageSize.height - 2*kBorderInset - 2*kMarginInset)
lineBreakMode:UILineBreakModeWordWrap];
CGRect renderingRect = CGRectMake(kBorderInset + kMarginInset, kBorderInset + kMarginInset + 50.0, pageSize.width - 2*kBorderInset - 2*kMarginInset, stringSize.height);
[textToDraw drawInRect:renderingRect
withFont:font
lineBreakMode:UILineBreakModeWordWrap
alignment:UITextAlignmentLeft];
}
また、PDFからテキストを取得することは可能ですか(テキストのみが含まれている場合)?
お知らせ下さい。