iOS Quartz embed font in pdf
Asked Answered
E

1

7

I'm trying to generate a PDF page with text that has custom symbols (e.g. "€") using a custom font. I've created a PDF context and page using UIGraphicsBeginPDFContextToData and UIGraphicsBeginPDFPage. My code for rendering text looks something like:

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 the €-symbol works (because of CTFontGetGlyphsForCharacters), but the font is not embedded in the pdf. Is there any way to do this?

Epiboly answered 7/3, 2012 at 10:52 Comment(2)
If you use a different font -- does it get embedded in the PDF? Or is it only this particular font that doesn't get embedded?Terebinthine
I ended up using on of the system fonts 'HelveticaNeue' with witch it works => question remains unanswered.Epiboly
D
4

I have fought with this for quite a while and it turned out that TTF is automagically embedded while OTF is not. Converting my font just worked.

Diestock answered 30/12, 2013 at 2:7 Comment(1)
Thanks, this worked for me! This should be chosen as the correct answer.Pietra

© 2022 - 2024 — McMap. All rights reserved.