PDF 파일에서 텍스트의 다른 모든 글꼴 이름을 추출하려고합니다. iTextSharp DLL을 사용하고 있으며 아래 코드는 내 코드입니다.PDF에서 텍스트의 글꼴 이름을 가져 오는 방법은 무엇입니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text.pdf.parser;
using iTextSharp.text.pdf;
namespace GetFontName
{
class Program
{
static void Main(string[] args)
{
PdfReader reader = new PdfReader("C:/Users/agnihotri/Downloads/Test.pdf");
HashSet<String> names = new HashSet<string>();
PdfDictionary resources;
for (int p = 1; p <= reader.NumberOfPages; p++)
{
PdfDictionary dic = reader.GetPageN(p);
resources = dic.GetAsDict(PdfName.RESOURCES);
if (resources != null)
{
//gets fonts dictionary
PdfDictionary fonts = resources.GetAsDict(PdfName.FONT);
if (fonts != null)
{
PdfDictionary font;
foreach (PdfName key in fonts.Keys)
{
font = fonts.GetAsDict(key);
string name = font.GetAsName(iTextSharp.text.pdf.PdfName.BASEFONT).ToString();
//check for prefix subsetted font
if (name.Length > 8 && name.ToCharArray()[7] == '+')
{
name = String.Format("%s subset (%s)", name.Substring(8), name.Substring(1, 7));
}
else
{
//get type of fully embedded fonts
name = name.Substring(1);
PdfDictionary desc = font.GetAsDict(PdfName.FONTDESCRIPTOR);
if (desc == null)
name += "no font descriptor";
else if (desc.Get(PdfName.FONTFILE) != null)
name += "(Type1) embedded";
else if (desc.Get(PdfName.FONTFILE2) != null)
name += "(TrueType) embedded ";
else if (desc.Get(PdfName.FONTFILE3) != null)
name += name;//("+font.GetASName(PdfName.SUBTYPE).ToString().SubSTring(1)+")embedded';
}
names.Add(name);
}
}
}
}
var collections = from name in names
select name;
foreach (string fname in collections)
{
Console.WriteLine(fname);
}
Console.Read();
}
}
}
내가 얻고 출력은 입력으로 모든 PDF 파일에 대한 "Glyphless 글꼴"더 폰트 기술자 "입니다 다음과 같이 입력 파일에 대한 링크는 다음과 같습니다.
https://drive.google.com/open?id=0B6tD8gqVZtLiM3NYMmVVVllNcWc
PdfReader 독자 = 새로운 PdfReader ("C : /Users/agnihotri/Downloads/Test.pdf"); - 파일의 경로를 다시 확인하십시오. 코드가 정상적으로 표시되므로 문제 일 수 있습니다. 또한 스크립트를 복사하여 인터넷에서 붙여 넣어 복사하는 경우 디버깅을 추가하는 것이 좋습니다. –