在Windows下使用Ghostscript压缩pdf文件大小

Ghostscript 下载安装

  1. 下载和安装

    官方网站下载地址

  2. 配置环境变量

    高级系统设置中添加环境变量

  3. 使用

    cmd 中使用如下命令进行 pdf 压缩。

    1
    
    gswin64c.exe -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile=output.pdf input.pdf
    

问题解决

在powershell中压缩报错

现象

powershell 使用上述的压缩命令报错如下:

1
2
3
4
5
6
GPL Ghostscript 10.01.1 (2023-03-27)
Copyright (C) 2023 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
GPL Ghostscript 10.01.1: Device 'pdfwrite' requires an output file but no file was specified.
**** Unable to open the initial device, quitting.
解决方法

cmd 中运行压缩命令而不是在 powershell 中运行