You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python docx2pdf时如何屏蔽输出的HBox进度条相关提示信息

解决方案

方法1:使用库原生参数(推荐,适用于docx2pdf 0.1.8及以上版本)

convert 方法原生提供了disable_progress_bar参数,直接设为True即可关闭进度条输出:

from docx2pdf import convert
convert(path, disable_progress_bar=True)

方法2:临时重定向标准输出(兼容所有版本)

如果你的docx2pdf版本较低没有上述参数,可以通过临时重定向标准输出的方式吞掉所有打印内容:

from docx2pdf import convert
from contextlib import redirect_stdout
import io

# with块内的所有标准输出都会被暂存到内存中,不会打印到控制台
with redirect_stdout(io.StringIO()):
    convert(path)

如果上述方法仍有残留输出,可以同时重定向标准错误流:

from docx2pdf import convert
from contextlib import redirect_stdout, redirect_stderr
import io

with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
    convert(path)

内容的提问来源于stack exchange,提问作者ASE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 12:18:03