Añado los fuentes de java
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Created on 22-nov-2005
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package com.tarisan.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import javax.print.*;
|
||||
import javax.print.attribute.*;
|
||||
import javax.print.attribute.standard.*;
|
||||
|
||||
/**
|
||||
* @author Roumen
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class Prueba {
|
||||
|
||||
|
||||
public void print() {
|
||||
|
||||
System.out.println("Dentro de print");
|
||||
String strPdfName = "CSM.pdf";
|
||||
String path = "C:\\Tomcat\\webapps\\tarisan\\peticiones";
|
||||
strPdfName = path + "/" + strPdfName;
|
||||
String osName = System.getProperty("os.name" );
|
||||
|
||||
try {
|
||||
|
||||
//FOR WINDOWS 95 AND 98 USE COMMAND.COM
|
||||
if(osName.equals("Windows 95") || osName.equals("Windows 98")){
|
||||
System.out.println("Dentro del IF");
|
||||
Runtime.getRuntime().exec("command.com /C start acrord32 /p " + strPdfName);
|
||||
}
|
||||
//FOR WINDOWS NT/XP/2000 USE CMD.EXE
|
||||
else {
|
||||
System.out.println("Dentro de else");
|
||||
Runtime.getRuntime().exec("cmd.exe start /C acrord32 /p " + strPdfName);
|
||||
//String cadena = "c:\\windows\\system32\\cmd";
|
||||
/*
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
String cadena = "cmd";
|
||||
System.out.println("cadena2: " + cadena);
|
||||
Process proc = rt.exec(cadena);
|
||||
int exitVal = proc.waitFor();
|
||||
*/
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void print1() {
|
||||
|
||||
/* Use the pre-defined flavor for a GIF from an InputStream */
|
||||
//DocFlavor flavor = new DocFlavor("text/plain","java.io.InputStream");
|
||||
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
|
||||
|
||||
System.out.println("1");
|
||||
|
||||
/* Create a set which specifies how the job is to be printed */
|
||||
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
|
||||
aset.add(MediaSizeName.NA_LETTER);
|
||||
aset.add(new Copies(1));
|
||||
System.out.println("2");
|
||||
|
||||
/* Locate print services which can print a GIF in the manner specified */
|
||||
//PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);
|
||||
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
|
||||
|
||||
System.out.println("3");
|
||||
if (pservice != null) {
|
||||
|
||||
/* Create a Print Job */
|
||||
System.out.println("Found a suitable printers: " + pservice);
|
||||
DocPrintJob printJob = pservice.createPrintJob();
|
||||
|
||||
/* Create a Doc implementation to pass the print data */
|
||||
//FileInputStream textSt;
|
||||
//File printFile = new File("C:/Tomcat/webapps/tarisan/peticiones/CSM.PDF");
|
||||
File printFile = new File("C:/tarisan/indices.txt");
|
||||
FileInputStream textSt;
|
||||
|
||||
try {
|
||||
textSt = new FileInputStream(printFile);
|
||||
byte[] bytesLeidos = new byte[10];
|
||||
textSt.read(bytesLeidos);
|
||||
for (int i=0;i<bytesLeidos.length;i++)
|
||||
System.out.println(bytesLeidos[i]);
|
||||
|
||||
Doc doc = new SimpleDoc(textSt, flavor, null);
|
||||
//Doc doc = new SimpleDoc
|
||||
|
||||
try {
|
||||
printJob.print(doc, aset);
|
||||
} catch (PrintException e) {
|
||||
System.out.println(e);
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("");
|
||||
System.out.println("--------------------------------");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.print("file not found outor");
|
||||
} catch (Exception ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
/* Print the doc as specified */
|
||||
} else {
|
||||
System.out.println("No suitable printers");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user