I am trying to create a PDF page with text that has custom characters (like "€") using a special font. I created the context and the PDF page using UIGraphicsBeginPDFContextToData and UIGraphicsBeginPDFPage. My code for displaying text looks something like this:
NSString *fontFile = [[NSBundle mainBundle] pathForResource:@"somefont.otf" ofType:nil]; CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename([fontFile cStringUsingEncoding:NSASCIIStringEncoding]); CGFontRef cgfont = CGFontCreateWithDataProvider(dataProvider); CTFontRef ctfont = CTFontCreateWithGraphicsFont(cgfont, 10, NULL, NULL); CFRelease(dataProvider); NSString *text = @"Hello €"; int len = [text length]; CGGlyph glyphs[len]; CTFontGetGlyphsForCharacters(ctfont, (const unichar*)[text cStringUsingEncoding:NSUnicodeStringEncoding], glyphs, len); CGContextSetTextDrawingMode(_context, kCGTextFill); CGContextShowGlyphsAtPoint(_context, 10, 10, glyphs, len); CFRelease(cgfont); CFRelease(ctfont);
Rendering work "-character" (due to CTFontGetGlyphsForCharacters), but the font is not embedded in pdf. Is there any way to do this?
toucan
source share