如何检测字体在PDF中使用的粗体/斜体/平面

时间:2013-05-22 17:31:24

标签: pdf mupdf

使用MuPDF库从PDF中提取内容时,我得到的字体名称不仅仅是字体。

我猜(虽然不是正确的方式,例如字体名称中的粗体)或者还有其他方法可以检测到特定字体是粗体/斜体/普通字体。

2 个答案:

答案 0 :(得分:1)

     i had used to itextsharp to extract font-family ,font color etc 

     public void Extract_inputpdf()
        {

            text_input_File = string.Empty;

            StringBuilder sb_inputpdf = new StringBuilder();
            PdfReader reader_inputPdf = new PdfReader(path); //read PDF
      for (int i = 0; i <=reader_inputPdf.NumberOfPages ; i++)
            {

                TextWithFont_inputPdf inputpdf = new TextWithFont_inputPdf();



                text_input_File = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader_inputPdf, i, inputpdf);


                sb_inputpdf.Append(text_input_File);





                input_pdf = sb_inputpdf.ToString();


            }
            reader_inputPdf.Close();
            clear();

        }

     public class TextWithFont_inputPdf : iTextSharp.text.pdf.parser.ITextExtractionStrategy
        {
      public void RenderText(iTextSharp.text.pdf.parser.TextRenderInfo renderInfo)
            {

                string curFont = renderInfo.GetFont().PostscriptFontName;

       string divide = curFont;
                string[] fontnames = null;

    //split the words from postscript if u want separate. it will be in this


             }
}
  public string GetResultantText()
        {


            return result.ToString();
        }

答案 1 :(得分:0)

PDF规范包含允许您指定字体样式的条目。然而不幸的是,在现实世界中,你经常会发现这些都不存在。

如果引用了字体而不是嵌入字体,这通常意味着你会遇到字体的PostScript名称。它需要一些启发式方法,但通常这个名称提供了足够的风格线索。听起来这就是你的所在。

如果嵌入了字体,您可以解析它并尝试从嵌入字体程序中查找样式信息。如果它是子集,那么在理论上这些信息可能会被删除,但总的来说我认为它不会。但是,解析TrueType / OpenType字体很无聊,你可能觉得不值得。

我在ABCpdf .NET软件组件上工作,所以我的回复可能包含基于ABCpdf的概念。这就是我所知道的。 :-)“

相关问题