iOS石英嵌入pdf中的字体 [英] iOS Quartz embed font in pdf
问题描述
我正在尝试使用自定义字体生成包含自定义符号(例如€)的文本的PDF页面。我使用UIGraphicsBeginPDFContextToData和UIGraphicsBeginPDFPage创建了一个PDF上下文和页面。我的渲染文本代码如下所示:
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);
渲染€-symbol有效(因为CTFontGetGlyphsForCharacters),但字体未嵌入pdf中。有没有办法做到这一点?
Rendering the €-symbol works (because of CTFontGetGlyphsForCharacters), but the font is not embedded in the pdf. Is there any way to do this?
推荐答案
我已经与之斗争了很长一段时间,事实证明TTF是自动的嵌入而OTF不是。转换我的字体刚刚工作。
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.
这篇关于iOS石英嵌入pdf中的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!