压缩pdf文件(使用ghostscript插件需要安装)

1.查看是否安装成功


2.安装好后方法如下
/**
 *
 * @param settings
 * 1、/screen 选择类似于Acrobat Distiller“屏幕优化”设置的低分辨率输出。(生成文件最小)
 * 2、/ebook 选择类似于Acrobat Distiller“电子书”设置的中等分辨率输出。
 * 3、/printer 选择类似于Acrobat Distiller“打印优化”设置的输出。
 * 4、/prepress 选择类似于Acrobat Distiller“印前优化”设置的输出。
 * 5、/default 选择意图在各种用途中有用的输出,这可能是以较大的输出文件为代价的。
 *
 *
 *
 * @param sourceFilePath 源文件完整路径
 * @param targetFilePath 目标文件完整路径
 * @return
 */
public  String getCommand(String settings,String sourceFilePath,String targetFilePath) {
   String perfix = null;
   if(System.getProperty("os.name").toUpperCase() .contains("WINDOWS")){
      perfix = "cmd /c E:\\ghos\\gs9.27\\bin\\gswin64.exe";
   }  else {
      perfix = "gs";
   }
   return perfix+" -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="+settings+
         " -dNOPAUSE -dQUIET -dBATCH -sOutputFile="+targetFilePath+" "+sourceFilePath;
}

@Test
public  void getPdf() throws InterruptedException, IOException {
   String trim = getCommand("/screen","D:\\pdf\\pdf1\\18511515111303.pdf","D:\\pdf\\pdf1\\666.pdf").trim();
   System.out.println(trim);
   Process exec = Runtime.getRuntime().exec(trim);

}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值