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); }
压缩pdf文件(使用ghostscript插件需要安装)
最新推荐文章于 2025-03-17 00:15:00 发布