【发布时间】:2013-09-16 12:22:53
【问题描述】:
我正在尝试使用自定义字体创建新的 PDF。
我加载了我的自定义字体,我可以在所有应用程序中使用它,但是当我尝试使用它创建我的 PDF 时,系统字体被打印出来。
我正在使用 NSString UIKit Additions。
+(UIFont *)imagoBook:(float)size{
return [UIFont fontWithName:@"Imago-Book" size:size];
}
-(NSData *)createPDFfromUIView
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, self.bounds, nil);
UIGraphicsBeginPDFPage();
UIFont *imagoBook13 = [ROCTextsInformation imagoBook:13];
[@"Test" drawAtPoint:CGPointZero withFont:imagoBook13];
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"t.pdf"];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
return pdfData;
}
事实上,我在视图中绘制了相同的上下文,字体写得很完美,但不是在 pdf 中。
我正在为字体使用 otf 文件。
谢谢
【问题讨论】:
-
什么是
imagoBook10? -
这里的信息可能会让您感兴趣:*.com/questions/8980388/ios-embed-font-in-pdf
-
感谢 ipmcc 提供的信息。我做了更多的测试,我检查了问题可能出在文件字体“otf”的类型上。我已经用其他“otf”文件进行了测试,得到了相同的结果,但是我用“ttf”文件进行了测试,它工作得很好。
标签: ios objective-c pdf quartz-2d cgcontextref