1.导出图片
package cn. net. haotuo. pojo ;
import java. io. * ; public class GhostscriptExample { public static void main ( String [ ] args) { String gsPath = "C:/Program Files/gs/gs9.54.0/bin/gswin64c.exe" ; String inputFilePath = "C:\\Users\\Administrator\\Desktop\\1050g白卡双面哑膜(5张)《507x457》《4种》.pdf" ; String outputFilePath = "C:\\Users\\Administrator\\Desktop\\1050g白卡双面哑膜(5张)《507x457》《4种》.png" ; String command = gsPath + " -dNOPAUSE -dBATCH -sDEVICE=png16m -r300 -sOutputFile=" + outputFilePath + " -f" + inputFilePath; run ( command) ; } public static void run ( String command) { System . out. println ( command) ; try { Process process = Runtime . getRuntime ( ) . exec ( command) ; int exitCode = process. waitFor ( ) ; if ( exitCode == 0 ) { System . out. println ( "Conversion successful!" ) ; } else { System . out. println ( "Conversion failed with error code: " + exitCode) ; InputStream errorStream = process. getErrorStream ( ) ; BufferedReader errorReader = new BufferedReader ( new InputStreamReader ( errorStream) ) ; String line; while ( ( line = errorReader. readLine ( ) ) != null ) { System . out. println ( line) ; } } } catch ( IOException | InterruptedException e) { e. printStackTrace ( ) ; } }
}