Java calls GSview to print PDF, java calls gsviewpdf
Preface
In a previous article, I introduced the Java PrintService API. Although it supports printing, it does not have the ability to interpret documents such as PDF and MS Word.
In addition, the support for Post Script standard printers is usually expensive, and cheap printers (using host-based Drivers) on the market are basically not supported.
In addition, the previous article provided the use of Adobe Reader to plug-in PDF printing. This article adopts the same method, but only GSview.
Compared with Adobe Reader, GSview can achieve silent printing, because when I use Adobe Reader, an Adobe Reader Center window will pop up, which is disgusting ~ The solution is not found.
This does not happen when GSView is used.
Preparations
First, go to the GSView official website to download the latest version of GSview,
I am using gsv50w32.exe and Ghostscript 9.15The two versions must match. The former is the main program, and the latter is something like a script interpreter (ENGINE) or an environment ~
Usage
Public static void printByGSview (String printerName, String filePath) {try restarting runtime.getruntime(cmd.exe c ("cmd.exe/C gsprint-printer \" "+ printerName +" \ "" + filePath );} catch (IOException e) {e. printStackTrace ();}}
The-printer parameter specifies the printer Based on the name.