_Please provide all mandatory information!_
First of all, I use Chinese.
There are some extra spaces when extracting text.
After testing, using the "pdfminer" package does not have these extra spaces.
In addition, when performing a text search, these extra spaces will affect the matching of the results.
import fitz
pdf = fitz.open('用水定额.pdf')
pdf.getPageText(4)
# The result is:
"""
DB41/T 958—2020
农业与农村生 活用 水定额
1范 围
本标准规 定了农业与农村生 活用 水定额 的 术语 和定义、灌溉用 水定额 使用 说 明、灌溉分区、灌溉基
本用 水定额 修正系 数、种 植业灌溉基本用 水定额 、林业灌溉基本用 水定额 、畜 牧 业用 水定额 、渔业用 水
定额 和农村生 活用 水定额
。
本标准适 用 于农业与农村生 活的 用 水定额 管 理
。
2规 范 性引用 文件
下列文件对于本文件的 应用 是必不可少的 。凡是注日期的 引用 文件, 仅注日期的 版 本适 用 于本文件。
凡是不注日期的 引用 文件, 其最新版 本( 包括所有的 修改单) 适 用 于本文件。
GB/T 4754—2017国民经 济行 业分类
GB/T 29404—2012灌溉用 水定额 编 制导则
GB/T 50363—2018节 水灌溉工程 技术标准
3术语 和定义
下列术语 和定义适 用 于本文件。
3. 1
用 水定额
一定时期内在一定的 技术和管 理 条件下, 按照相 应核算 单元确 定的 、符 合节 约 用 水要 求的 各类 用 水
户单位用 水量 的 限 额 , 不包括输 水损失水量
。
3.2
农业用 水定额
一定时期内按照单位面 积 、单个畜 禽 核算 的 种 植业、林业、渔业和畜 牧 业用 水量 的 限 额
。
3. 3
灌溉基本用 水定额
在规 定水文年型和参照灌溉条件下, 核定的 某种 作物 在一个生 育 期内( 多年生 作物 以一年为期) 田
间 单位面 积 灌溉用 水量 的 限 额 , 含田 间 灌溉损失水量 和附 加用 水定额 ( 包括播前灌溉和泡田 用 水等 )
。
注1:水文年型为50%和75%, 其中50%为平水年, 75%为中等 干旱年。
注2:参照灌溉条件为地面 灌溉。
3.4
灌溉基本用 水定额 修正系 数
反映灌溉方法、种 植条件对参照灌溉条件下灌溉基本用 水定额 影响程 度的 系 数。
3. 5
地面 灌溉
采 用 沟、畦 等 地面 设 施, 对作物 进 行 灌溉的 方法。
"""
# When I use pdfminer, the test result is:
"""
DB41/T 958—2020
农业与农村生活用水定额
1范围
本标准规定了农业与农村生活用水定额的术语和定义、灌溉用水定额使用说明、灌溉分区、灌溉基
本用水定额修正系数、种植业灌溉基本用水定额、林业灌溉基本用水定额、畜牧业用水定额、渔业用水
下列文件对于本文件的应用是必不可少的。凡是注日期的引用文件,仅注日期的版本适用于本文件。
凡是不注日期的引用文件,其最新版本(包括所有的修改单)适用于本文件。
定额和农村生活用水定额。
本标准适用于农业与农村生活的用水定额管理。
2规范性引用文件
GB/T 4754—2017国民经济行业分类
GB/T 29404—2012灌溉用水定额编制导则
GB/T 50363—2018节水灌溉工程技术标准
3术语和定义
用水定额
下列术语和定义适用于本文件。
3. 1
3.2
3. 3
3.4
3. 5
农业用水定额
灌溉基本用水定额
注2:参照灌溉条件为地面灌溉。
灌溉基本用水定额修正系数
一定时期内在一定的技术和管理条件下,按照相应核算单元确定的、符合节约用水要求的各类用水
户单位用水量的限额,不包括输水损失水量。
一定时期内按照单位面积、单个畜禽核算的种植业、林业、渔业和畜牧业用水量的限额。
在规定水文年型和参照灌溉条件下,核定的某种作物在一个生育期内(多年生作物以一年为期)田
间单位面积灌溉用水量的限额,含田间灌溉损失水量和附加用水定额(包括播前灌溉和泡田用水等)。
注1:水文年型为50%和75%,其中50%为平水年,75%为中等干旱年。
反映灌溉方法、种植条件对参照灌溉条件下灌溉基本用水定额影响程度的系数。
地面灌溉
采用沟、畦等地面设施,对作物进行灌溉的方法。
"""
fix the bug, Just like the result of pdfminer
None
win32
PyMuPDF 1.18.0: Python bindings for the MuPDF 1.18.0 library.
Version date: 2020-10-06 07:15:59.
Built for Python 3.8 on win32 (64-bit).
None
Please try the flags bit TEXT_INHIBIT_SPACES: page.getText("text", flags=fitz.TEXT_INHIBIT_SPACES).
MuPDF uses heuristics to decide whether or not a distance between letters is big enough to assume a space and consequently generate one on output.
The search methods as well have and react to the same parameter.
Tested your file with and it looks fine as far as I can say without knowing any Chinese.
Searching also works.
Please try the flags bit
TEXT_INHIBIT_SPACES:page.getText("text", flags=fitz.TEXT_INHIBIT_SPACES).MuPDF uses heuristics to decide whether or not a distance between letters is big enough to assume a space and consequently generate one on output.
The search methods as well have and react to the same parameter.
I tested my other files and it worked well, thank you
Please also have a look at the other bits of this flags fields:
E.g. if you know you only are interested in text extraction, you should switch off extracting images - a _huge_ impact on performance and memory consumption ...
Most helpful comment
I tested my other files and it worked well, thank you