Write PDF text to a PDFContext in iOS

天涯浪子 提交于 2019-12-01 08:02:28

It's definitely possible. Here's a tutorial that shows how to generate and display a PDF document, with text, in iOS 5.

When I downloaded and ran the project, the text did not appear to be rasterized when I zoomed in. When I opened the generated PDF in Preview in OS X, I could select and copy the text.

This example uses Core Text to draw the text into the CGContext. Should be easy to change +[PDFRenderer drawText] to try other methods, if you'd like to experiment.

For instance, I changed it to use code similar to yours, and it worked fine:

CGRect text_rect = { 0, 100, 300, 50 };
UIFont *font = [UIFont systemFontOfSize:12];
NSString * str = @"Added foo bar";
[str drawInRect:text_rect withFont:font];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!