【问题标题】:Extract text from sections of a Latex exported PDF, using Python使用 Python 从 Latex 导出的 PDF 的部分中提取文本
【发布时间】:2017-09-28 10:24:07
【问题描述】:

我有用 Latex 编写的科学研究论文的 PDF 文件。 每篇研究论文都有“简介”、“相关工作”等部分,我想分别提取每个部分下的文字。

此 PDF 在第 1 页包含“摘要”和“简介”部分。 对于“摘要”部分,我想检索斜体文本。对于“介绍”,我希望所有这些段落都在其部分中。

如果我有 Latex 源文件,我可以进行一些数据挖掘并根据 \section{} 关键字提取文本

因此我在 Python3 中尝试了一些方法,例如将 pdf 转换为乳胶[link],但建议的软件要么与我的系统不兼容(Ubuntu 16.04),要么是付费软件。我尝试使用 textract,但它没有从 PDF 中提取部分的选项。

有人知道如何从使用 Latex 制作的 PDF 中提取部分吗?

【问题讨论】:

  • 从 arXiv 下载乳胶源文件然后用 pandoc 处理它们可能更容易。

标签: python python-3.x pdf latex


【解决方案1】:

我不知道如何使用 R 来执行此操作,但如果您将所有 PDF 文件放在一个文件夹中,循环浏览它们并将每个文件转换为一堆 Word 文档,您可以轻松地使用 VBA 来完成任务。

Sub SelectBetweenHeadings()
    With Selection
        .GoTo What:=wdGoToHeading, Which:=wdGoToPrevious
        .Collapse
        Dim curRange As Range
        Set curRange = .Range
        .Extend
        .GoTo What:=wdGoToHeading, Which:=wdGoToNext
        If .Range = curRange Then
            .EndKey Unit:=wdStory
        End If
        .ExtendMode = False
    End With
End Sub

或者,为了更精确,试试这个。

Sub Macro1()
    Selection.WholeStory
    Selection.Collapse wdCollapseStart

    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Caption 1")
    With Selection.Find
        .Text = "2.3.1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = True
    End With
    Selection.Find.Execute
    Selection.Collapse wdCollapseStart

    Dim r1 As Range
    Set r1 = Selection.Range

    ' keep format settings, only change text
    Selection.Find.Text = "2.3.2"
    If Selection.Find.Execute Then
        Selection.Collapse wdCollapseStart
    Else
        Selection.WholeStory
        Selection.Collapse wdCollapseEnd
    End If
    Dim r2 As Range
    Set r2 = ActiveDocument.Range(r1.Start, Selection.Start)
    r2.Select

End Sub

【讨论】:

  • 恐怕我不知道 R .. 我需要用 Python 编写代码:/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多