在Unix或Windows中,我希望将此字典转换为Python dictionary。我复制了PDF字典的内容,并将它们放入一个.rtf文件中,打算用read对它们进行read。然而,它提供了如下内容:
A /e/ noun -- ABO系统的一种人类血型,含有A抗原(注:A型的一些人可以向同一组或AB类的人献血,也可以接受A型或O型患者的血液) AA 腹胀/bdɒmn(ə)l ds 10ʃ(ə)n/名词 男人因为气体或液体而紧张。 一个 腹胀 戒酒匿名者
从本质上说,它把PDF中的列压缩成了一种奇怪的混合。如何将PDF转换为文本,以使列受到尊重?换句话说,期望的输出是:
A /e/ noun -- ABO系统的一种人类血型,含有A抗原(注:A型的一些人可以向同一组或AB类的人献血,也可以接受A型或O型患者的血液) 戒酒匿名者
...and等
发布于 2015-03-30 17:43:52
基本上,您有两个选项可以进入文本:
对于first选项,我建议您首先尝试pdftotext,但是使用参数-layout。(还有其他工具,如泰特,来自PDFlib人员的文本提取工具包,如果pdftotext不够好,您可以尝试使用它。)
为了使用Ghostscript和其他工具遵循第二个选项的道路,您可能需要查看我对以下问题的答案:
pdftotext -layout
您可以使用命令行工具pdftotext进行尝试。你必须决定它对你的目的是否“足够好”。
以下命令仅从第8页(具有双列布局的第一页)提取文本,并将其打印到<stdout>
$ pdftotext -f 8 -l 8 -layout \
Dictionary+of+Medical+Terms+4th+Ed.-+\(Malestrom\).pdf - \
| head -n 30在以下方面的成果:
Medicine.fm Page 1 Thursday, November 20, 2003 4:26 PM
A
A /e/ noun a human blood type of the ABO abdominal distension /bdɒmn(ə)l ds
A abdominal distension
system, containing the A antigen (NOTE: Some- tenʃ(ə)n/ noun a condition in which the abdo-
one with type A can donate to people of the men is stretched because of gas or fluid
same group or of the AB group, and can receive abdominal pain /b dɒmn(ə)l pen/ noun
abdominal pain
blood from people with type A or type O.) pain in the abdomen caused by indigestion or
AA
AA abbr Alcoholics Anonymous more serious disorders
A & E /e ənd i
/, A & E department /e ənd abdominal viscera /bdɒmn(ə)l vsərə/
A & E abdominal viscera
i
d pɑ
tmənt/ noun same as accident and
plural noun the organs which are contained in
emergency department the abdomen, e.g. the stomach, liver and intes-
A & E medicine /e ənd i
med(ə)sn/
A & E medicine
tines
abdominal wall /b dɒmn(ə)l wɔ
l/ noun
abdominal wall
noun the medical procedures used in A & E de-
partments muscular tissue which surrounds the abdomen
abdomino- /bdɒmnəυ/ prefix referring to
abdomino-注意-layout的使用!如果没有它,所提取的文本将如下所示:
Medicine.fm第1页,2003年11月20日(星期四)下午4:26下午4:26 A /e/ noun为人类血型,含A抗原(注: SomeA )
A型患者可以捐给同一群体或AB型患者,也可以接受A型或O型患者的血液。戒酒匿名A&E /eəand I /,A&E部门/eəand ipɑtmənt/名词与急诊科(ə)的n/名词急诊科急症室的医疗程序相同
A&E A&E医学部AB /ebi / noun人血型ABO系统,含A、B抗原AB
我注意到该文件在第8页上使用,但没有嵌入字体Courier、Helvetica、Helvetica-Bold、Times-Roman和Times-Italic。
这不会给文本提取带来问题,因为所有这些字体都使用/WinAnsiEncoding。
但是,还有其他字体,它们作为一个子集嵌入。这些字体确实使用/Custom编码,但它们不提供/ToUnicode表。此表是可靠的文本提取(将字形名称反向转换为字符名)所必需的。
我说的话可以在这张表上看到:
$ pdffonts -f 8 -l 8 Dictionary+of+Medical+Terms+4th+Ed.-+\(Malestrom\).pdf
name type encoding emb sub uni object ID
------------------------------ ----------- ------------- --- --- --- ---------
Helvetica-Bold Type 1 WinAnsi no no no 1505 0
Courier Type 1 WinAnsi no no no 1507 0
Helvetica Type 1 WinAnsi no no no 1497 0
MOEKLA+Times-PhoneticIPA Type 1C Custom yes yes yes 1509 0
Times-Roman Type 1 WinAnsi no no no 1506 0
Times-Italic Type 1 WinAnsi no no no 1499 0
IGFBAL+EuropeanPi-Three Type 1C Custom yes yes no 1502 0碰巧,我最近为一个新的GitHub项目手工编写了5个不同的PDF文件,并附带注释源代码。这5个文件为嵌入为子集的每个字体演示了正确的/ToUnicode表的重要性。在这里可以找到它们,以及解释更多细节的自述文件。
发布于 2015-03-28 16:33:21
您可以使用pdfminer从PDF:http://www.unixuser.org/~euske/python/pdfminer/中提取文本
发布于 2015-03-28 16:36:17
PDF文档对文档结构的概念很少。PDF内容流包括在页面上放置象形文字的指令,但放置顺序不必与文档结构相对应。
您没有说明您正在使用的平台。如果您使用的是OS,您可以使用PDFKit来实现您想要的结果。
https://stackoverflow.com/questions/29319533
复制相似问题