Skip to content

Instantly share code, notes, and snippets.

@sandroqz
Created March 10, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandroqz/3d932b1190de7b375885d98fe7468551 to your computer and use it in GitHub Desktop.
Save sandroqz/3d932b1190de7b375885d98fe7468551 to your computer and use it in GitHub Desktop.
package br.com.exemplo;
import org.ghost4j.Ghostscript;
import org.ghost4j.GhostscriptException;
public class ComprimePdf {
public static void main(String[] args) {
Ghostscript gs = Ghostscript.getInstance();
String[] gsArgs = new String[9];
// gsArgs[0] = "-I/usr/local/Cellar/ghostscript/9.20/bin/";
gsArgs[0] = "-gs";
gsArgs[1] = "-sDEVICE=pdfwrite";
gsArgs[2] = "-dCompatibilityLevel=1.4";
gsArgs[3] = "-dPDFSETTINGS=/screen"; // ebook ou screen
gsArgs[4] = "-dNOPAUSE";
gsArgs[5] = "-dQUIET";
gsArgs[6] = "-dBATCH";
gsArgs[7] = "-sOutputFile=/Users/sandro/output.pdf";
gsArgs[8] = "/Users/sandro/digitalizar0025.pdf";
try {
gs.initialize(gsArgs);
gs.exit();
} catch (GhostscriptException e) {
// TODO Auto-generated catch block
System.out.println("Erro: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment