我有一个包含图像的 pdf 文件,我想减小其大小,以便将其上传到有大小限制的网站。
那么,如何从命令行减小 pdf 文件的大小呢?
答案1
您可以使用gs
- GhostScript(PostScript 和 PDF 语言解释器和预览器)如下:
- 放pdf写入作为输出设备
-sDEVICE=pdfwrite
- 使用适当的
-dPDFSETTINGS
.
从文档:
-dPDFSETTINGS=
配置
将“蒸馏器参数”预设为四个预定义设置之一:
- /屏幕选择类似于 Acrobat Distiller“屏幕优化”设置的低分辨率输出。
- /电子书选择类似于 Acrobat Distiller“电子书”设置的中等分辨率输出。
- /打印机选择类似于 Acrobat Distiller“打印优化”设置的输出。
- /印前选择类似于 Acrobat Distiller“印前优化”设置的输出。
- /默认选择旨在用于多种用途的输出,可能会以更大的输出文件为代价。
例子:
$ du -h file.pdf
27M file.pdf
$ gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -q -o output.pdf file.pdf
$ du -h output.pdf
900K output.pdf
答案2
ps2pdf input.pdf output.pdf
我得到了答案询问 ubuntu这对我有用。实际上减少了 18.1Mb 至 1.0Mb
答案3
如果 PDF 文件完全由图像数据组成;
pdftk inputFile.pdf burst
mogrify -density 300 -format jpg -quality 20 pg_*.pdf
convert *.jpg -auto-orient outputFile.pdf
密度值可以与源图像的密度相匹配(例如300 dpi),但jpeg 质量应低于源图像(例如20)。
答案4
你可以试试这个:
$ time pdftk myFile.pdf output myFile__SMALLER.pdf compress
GC Warning: Repeated allocation of very large block (appr. size 16764928):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 8384512):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 11837440):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 8384512):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 33525760):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 7254016):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 34041856):
May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 33525760):
May lead to memory leak and poor performance.
real 0m23.677s
user 0m23.142s
sys 0m0.540s
$ du myFile*.pdf
108M myFile.pdf
74M myFile__SMALLER.pdf
gs
在这种情况下,对于 107.5MiB 输入文件,它的速度比压缩速度快,但最多可压缩 30%。