Search code examples
iphoneobjective-cpdfcgpdf

How to find the pdf document font using CGPDFScanner in iphone app?


I am getting the "F1.0" in Tf callback method in CGPDFScanner. But I am not getting how I can go ahead with "F1.0"

After doing some search I come to know that it is king of font detail. How Can I Decode this value.


Solution

  • The font objects are located in the /Resources dictionary. If you are parsing a page content stream, you get the font object like this: get the /Resources dictionary from the Page dictionary. From the /Resources dictionary get the /Font dictionary. From the /Font dictionary get the font dictionary with your label, /F1.0. Basically the code looks like this (you need to add the error handling code because these dictionaries can be NULL):

    CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(pdfPage);
    
    CGPDFDictionaryRef resourcesDictionary;
    CGPDFDictionaryGetDictionary(pageDictionary, "Resources", &resourcesDictionary);
    
    CGPDFDictionaryRef fontDictionary;
    CGPDFDictionaryGetDictionary(resourcesDictionary, "Font", &fontDictionary);
    
    CGPDFDictionaryRef f10FontDictionary;
    CGPDFDictionaryGetDictionary(fontDictionary, "F1.0", &f10FontDictionary);
    

    The f10FontDictionary will contain the font object. The entries in this dictionary are detailed in the PDF specification.