1

I'm trying to create a new PDF with custom font.

I load my custom font and I can use it in all app, but when I tried to use it creating my PDF, the System font is printed.

I'm using 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;
}

In fact I'm drawing the same context in a view and the font is written perfectly but not in the pdf.

I'm using otf files for the font.

Thankssss

xarly
  • 2,054
  • 4
  • 24
  • 40
  • what is `imagoBook10`? – Kreiri Sep 16 '13 at 12:26
  • The information over here will likely interest you: http://stackoverflow.com/questions/8980388/ios-embed-font-in-pdf – ipmcc Sep 16 '13 at 13:21
  • Thanks for the infomation ipmcc. I have done more tests, and I have checked that the problem could be for the kind of file font 'otf'. I have tested with other 'otf' files and I get the same result, but I have test with 'ttf' file and it's work perfectly. – xarly Sep 18 '13 at 08:45

1 Answers1

2

Finally I have solved the problem converting the file .otf to .ttf, and it works!

xarly
  • 2,054
  • 4
  • 24
  • 40