Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何按具有特定大小或字体的标题拆分PDF_C#_Pdf_Split_Itext - Fatal编程技术网

C# 如何按具有特定大小或字体的标题拆分PDF

C# 如何按具有特定大小或字体的标题拆分PDF,c#,pdf,split,itext,C#,Pdf,Split,Itext,我正在尝试根据他的大小或字体,按他的标题拆分PDF 目前,我只能提取PDF的字体,但我需要知道大小或字体,以查看该文本是否为标题。我不知道如何用特定的大小或字体来阅读PDF,我知道它可以提取文本,但只是简单的文本,你怎么知道文本的大小或字体 顺便说一句,我已经能够通过他的书签和书签的孩子们来拆分PDF 但我需要更深入地拆分PDF。这就是为什么我试图让标题按它们分割PDF 我做了一些研究,但没有找到对这个案子有用的东西 这里有一些问题: 你怎么知道尺寸的 你是如何得到字体的 如何逐行迭代PDF 如

我正在尝试根据他的大小或字体,按他的标题拆分PDF

目前,我只能提取PDF的字体,但我需要知道大小或字体,以查看该文本是否为标题。我不知道如何用特定的大小或字体来阅读PDF,我知道它可以提取文本,但只是简单的文本,你怎么知道文本的大小或字体

顺便说一句,我已经能够通过他的书签和书签的孩子们来拆分PDF

但我需要更深入地拆分PDF。这就是为什么我试图让标题按它们分割PDF

我做了一些研究,但没有找到对这个案子有用的东西

这里有一些问题:

你怎么知道尺寸的

你是如何得到字体的

如何逐行迭代PDF

如果文本行有特定字体,如何检查

一些代码

HashSet<String> fontNames = 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)
    {
        //get 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(PdfName.BASEFONT).ToString();
                fontNames.Add(name);
            }

        }
    }
}
另一种方式 List fonts2=BaseFont.GetDocumentFontsreader

其他代码:获取文本

ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(reader, i, strategy);

words = currentText.Split('\n');
for (int j = 0, len = words.Length; j < len; j++)
{
    line = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(words[j]));
}
我用了这个:

public void RenderTextiTextSharp.text.pdf.parser.TextRenderInfo renderInfo

renderInfo参数包含了我所需要的一切

renderInfo.GetFont().PostscriptFontName;  // Font Name
renderInfo.GetBaseline().GetStartPoint(); // Coordinates - (56.6929 , 727.8466, 1)
renderInfo.GetAscentLine().GetEndPoint(); // Coordinates - (96.78018, 737.1749, 1)

Encoding.UTF8.GetStringEncoding.UTF8.GetByteswords[j]-这实现了什么?要想按样式分析提取的文本,您需要扩展现有的文本提取策略或从草图创建新的文本提取策略。在这里,您可以更改结果并在其中集成样式信息,也可以按策略中已有的样式进行处理。这两种类型都有关于堆栈溢出的示例。哪种方法更好,取决于手头的用例。您好@mkl,谢谢您的回答,它确实帮助我知道我应该调查什么。昨天我尝试了一些东西,我可以得到我需要的东西。我使用了这个公共的void renderextitextsharp.text.pdf.parser.TextRenderInfo renderInfo,renderInfo参数包含了我需要的所有内容```renderInfo.GetFont.PostscriptFontName;renderInfo.GetBaseline.GetStartPoint;renderInfo.GetAscentLine.GetEndPoint```伟大的你可能想把它变成一个实际的答案,而不是一个简单的评论,然后你可以标记为接受的答案,以帮助其他人寻找答案。