如何使用iText检查PDF中的嵌入式字体

撞到

我想使用Itext / Itextsharp检查PDF中的Embedded字体

我已经使用Itexthsarp从PDF获取字体,下面的代码获取了PDF的字体集合bool embeededFont = false;

       iTextSharpLGPV.PdfReader reader = new iTextSharpLGPV.PdfReader(fileName);
        HashSet<String> names = new HashSet<string>();
        iTextSharpLGPV.PdfDictionary resources;
        for (int p = 1; p <= reader.NumberOfPages; p++)
        {
            iTextSharpLGPV.PdfDictionary dic = reader.GetPageN(p);
            resources = dic.GetAsDict(iTextSharpLGPV.PdfName.Resources);
            if (resources != null)
            {
                //gets fonts dictionary
                iTextSharpLGPV.PdfDictionary fonts = resources.GetAsDict(iTextSharpLGPV.PdfName.Font);
                if (fonts != null)
                {

                    iTextSharpLGPV.PdfDictionary font;

                    foreach (iTextSharpLGPV.PdfName key in fonts.Keys)
                    {
                        font = fonts.GetAsDict(key);
                        string name = font.GetAsName(iTextSharpLGPV.PdfName.Basefont).ToString();

                        //check for prefix subsetted font

                        if (name.Length > 8 && name.ToCharArray()[7] == '+')
                        {
                            name = String.Format("{0} subset ({1})", name.Substring(8), name.Substring(1, 7));

                        }
                        else
                        {
                            //get type of fully embedded fonts
                            name = name.Substring(1);
                            iTextSharpLGPV.PdfDictionary desc = font.GetAsDict(iTextSharpLGPV.PdfName.Fontdescriptor);
                            if (desc == null)
                                name += "no font descriptor";
                            else if (desc.Get(iTextSharpLGPV.PdfName.Fontfile) != null)
                                name += "(Type1) embedded";
                            else if (desc.Get(iTextSharpLGPV.PdfName.Fontfile2) != null)
                                name += "(TrueType) embedded ";
                            else if (desc.Get(iTextSharpLGPV.PdfName.Fontfile3) != null)
                                name += name;//("+font.GetASName(PdfName.SUBTYPE).ToString().SubSTring(1)+")embedded';
                        }

                        names.Add(name);
                    }
                }
            }
        }
mkl

正如评论中所阐明的,OP希望知道如何检查字体是否嵌入

请查看PDF规范中的“嵌入式字体程序”部分,例如,较旧的ISO 32000-1中的9.9部分:

表126总结了取决于字体程序表示形式的将字体程序嵌入PDF文件的方式。密钥应是字体描述符中用于引用字体文件流的名称。子类型应是字体文件流字典中子类型键(如果存在)的值下面给出了特定字体程序表示的更多详细信息。

表126 –各种字体类型的嵌入式字体组织

键-子类型-说明

FontFile - - - 1型字体程序,在所描述的原始(非紧)格式的Adobe Type 1字体格式此项可能出现在Type1MMType1字体字典的字体描述符中

FontFile2 - - - (PDF 1.1)TrueType字体程序,如在所描述的TrueType参考手册此项可能出现在TrueType字体字典的字体描述符中,或者出现在CIDFontType2CIDFont字典的(PDF 1.3)中

FontFile3 - Type1C-(PDF 1.2)Type 1 –紧凑字体格式(CFF)中表示的等效字体程序,如Adobe技术注释#5176 “紧凑字体格式规范”中所述此项可能出现在Type1MMType1字体字典的字体描述符中

FontFile3 - CIDFontType0C-(PDF 1.3)Type 0 CIDFont程序,以紧凑字体格式(CFF)表示,如Adobe技术注释#5176,紧凑字体格式规范中所述此项可能会出现在CIDFontType0 CIDFont词典的字体描述符中

FontFile3 - OpenType-(PDF 1.6)OpenType®字体程序,如OpenType规范v.1.4中所述(请参见参考书目)。OpenType是TrueType的扩展,它允许包含使用紧凑字体格式(CFF)的字体程序。...

因此,您应该在相应字体FontDescriptor字典中查找这些键,即从本质上讲,您在代码中所做的操作desc

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章