/* * PDFPrintLibClass.java * * Created on January 27, 2006, 10:28 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.me.pdfprint; /** * * @author mgosselin */ public class PDFPrintLibClass { /******************************************************************************************** * * printPDF * * Prints a PDF using Adobe Reader "/t" (print and terminate) * * @param File File to be printed, for example, C:\MYFILE.PDF * @param Printer Printer, for example, \\MYSERVER\MYPRINTER * **********************************************************************************************/ public static void printPDF(String pFile, String pPrinter) { final String PATH_ADOBE_READER = "C:\\Program Files\\Adobe\\Acrobat 7.0\\Reader\\AcroRd32.exe"; final String ADOBE_READER_PRINT_COMMAND = "/t"; final String SLASH = "/"; final String QUOTE = "\""; final String SPACE = " "; // Command to be executed String lCommand = QUOTE + PATH_ADOBE_READER + QUOTE + SPACE + ADOBE_READER_PRINT_COMMAND + SPACE + QUOTE + pFile + QUOTE + SPACE + QUOTE + pPrinter + QUOTE; System.out.println("[printPDF] Command to be executed : " + lCommand); Process lAdobeBackGroundProcess = null; Process lAdobeProcess = null; try { // Must create a background Adobe Reader process (don't ask why, just do it;-) lAdobeBackGroundProcess = Runtime.getRuntime().exec(PATH_ADOBE_READER); // Execute the Adobe Reader command "/t" (print and terminate) lAdobeProcess = Runtime.getRuntime().exec(lCommand); // Wait for Adobe Reader to complete int exitVal = lAdobeProcess.waitFor(); if ( exitVal != 0 ) { throw new Exception("[printPDF] Adobe Reader process exitVal : " + exitVal); } } catch (Exception e) { System.err.println("[printPDF] Error printing PDF : " + pFile); e.printStackTrace(); } finally { if (lAdobeBackGroundProcess != null) { lAdobeBackGroundProcess.destroy(); lAdobeBackGroundProcess = null; } } } /** Creates a new instance of PDFPrintLibClass */ public PDFPrintLibClass() { } }
by
raidho
2007-03-14 07:11
pdf
·
print
·
java
http://forum.java.sun.com/thread.jspa?threadID=293692&start=45&tstart=0
-
cached
-
mail it
-
history