Writing PDF text to PDFContext in iOS

This is pretty trivial to draw in a pdf context via:

UIGraphicsBeginPDFContextToFile(pdfFile, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(sheet.frame, nil);    
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGRect text_rect = ...
NSFont *font = ...
NSString * str = @"foo";
[str drawInRect:text_rect withFont:font];

...draw to context...

However, the text is clearly rasterized ... Is there a way to add pdf text to a pdf file? Thus, the user can select it, copy, etc. Perhaps through a library other than the main graphics?

+3
source share
1 answer

It is definitely possible. Here is a tutorial that shows how to create and display a PDF document with text in iOS 5.

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

Core Text CGContext. +[PDFRenderer drawText], , .

, , , , :

CGRect text_rect = { 0, 100, 300, 50 };
UIFont *font = [UIFont systemFontOfSize:12];
NSString * str = @"Added foo bar";
[str drawInRect:text_rect withFont:font];
+1

All Articles