IRONSOFTWAREHOME
PDF压缩
from ironpdf import *

pdf = PdfDocument("document.pdf")

# Quality parameter can be 1-100, where 100 is 100% of original quality
pdf.CompressImages(60)
pdf.SaveAs("document_compressed.pdf")

# Second optional parameter can scale down the image resolution according to its visible size in the PDF document. Note that this may cause distortion with some image configurations
pdf.CompressImages(90, True)
pdf.SaveAs("document_scaled_compressed.pdf")
pip install ironpdf
PDF压缩

PDF压缩

IronPDF for Python 可以通过 CompressImages 方法压缩嵌入的图像来减少 PDF 文档的文件大小,该方法接受质量等级和可选的图像缩放参数。

开始

using PdfDocument(path) 从文件中加载 PdfDocument,用所需质量级别调用 CompressImages,并将结果保存到新文件。

理解代码

  • PdfDocument("document.pdf"):打开现有 PDF 以进行修改。
  • CompressImages(quality):将文档中的所有图像压缩到指定的质量级别。 quality 是一个从 1 到 100 的整数,其中 100 保留原始质量,较低的值会以图像质量为代价来减小文件大小。
  • CompressImages(quality, scaleDownImages):当可选的第二个布尔参数设置为 True 时,还会根据每个图像在 PDF 中的可见尺寸缩小图像分辨率。 这可以使文件显著变小,但可能会对某些图像类型造成视觉伪影。
  • SaveAs(path):将压缩的 PDF 保存到指定的文件路径。

选择质量级别

质量使用案例
90–100接近无损,文件大小减少最小
60–80大多数文档的良好平衡
30–50适合电邮或网络分发的小文件
1–29最大压缩,显著质量损失
学习使用IronPDF for Python优化PDF吧!

准备开始了吗?

版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
Python 模块下载 PDF
using pip 安装

版本: 2026.9

  1. 下载 并安装 Python 3.7+。
  2. 如果尚未安装,请从 pypi.org 安装 pip。
  3. 在终端中执行上述命令。
Python PDF 模块
下载 模块

版本: 2026.9

手动安装到您的项目中

  1. 下载软件包
  2. 在终端中运行此命令
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

$999 起