title image


Smiley Re: Drucken von Postscript-Datei
Hallo,



zwei Möglichkeiten gibts da:



(1)



import java.io.*;

import java.awt.*;

import java.awt.Graphics;

import javax.print.*;

import javax.print.attribute.*;

import javax.print.attribute.standard.*;

import javax.print.event.*;



class Printz

{

public static void main(String[] args)

{





FileInputStream psStream = null;

System.out.println("psStream initialized");



try {

psStream = new FileInputStream("druckmich.txt");



System.out.println("psStream created");



} catch (FileNotFoundException ffne) {

System.out.println("file not found");

}





if (psStream == null) {

System.out.println("psStream has null value");

//return;

}





//DocFlavor flavor = new DocFlavor("text/plain", "java.io.InputStream");

DocFlavor flavor = new DocFlavor("application/octet-stream", "java.io.InputStream");





System.out.println("Doc Flavor created");



PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

aset.add(new Copies(1));

System.out.println("Attributes added");



SimpleDoc myDoc = new SimpleDoc(psStream, flavor, null);

System.out.println("SimpleDoc created");



PrintService pss[] = PrintServiceLookup.lookupPrintServices( null, null );



PrintServiceLookup.lookupPrintServices(flavor, aset);

if (pss.length > 0) {



DocPrintJob job = pss[0].createPrintJob();

try {

job.print(myDoc, aset);

System.out.println("print initialized");

} catch (PrintException pe) {

System.out.println(pe.toString());

}

}else {System.out.println("print übersprungen");}



}

}





(2)



import java.io.*;

import java.awt.*;

import java.awt.Graphics;

import javax.print.*;

import javax.print.attribute.*;

import javax.print.attribute.standard.*;

import javax.print.event.*;



class Printz

{

public static void main(String[] args)

{





FileInputStream psStream = null;

System.out.println("psStream initialized");



try {

psStream = new FileInputStream("druckmich.txt");



System.out.println("psStream created");



} catch (FileNotFoundException ffne) {

System.out.println("file not found");

}





if (psStream == null) {

System.out.println("psStream has null value");

//return;

}





//DocFlavor flavor = new DocFlavor("text/plain", "java.io.InputStream");

DocFlavor flavor = new DocFlavor("application/octet-stream", "java.io.InputStream");





System.out.println("Doc Flavor created");



PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

aset.add(new Copies(1));

System.out.println("Attributes added");



SimpleDoc myDoc = new SimpleDoc(psStream, flavor, null);

System.out.println("SimpleDoc created");



PrintService pss[] = PrintServiceLookup.lookupPrintServices( null, null );



PrintServiceLookup.lookupPrintServices(flavor, aset);

if (pss.length > 0) {



DocPrintJob job = pss[0].createPrintJob();

try {

job.print(myDoc, aset);

System.out.println("print initialized");

} catch (PrintException pe) {

System.out.println(pe.toString());

}

}else {System.out.println("print übersprungen");}



}

}





Etwas anpassen und dann sollte es wohl gehen, bin selber gerade am basteln. Die Methode mit dem Graphicskontext ist finde ich nicht so fummelig.



Gruss Martin (zehleNOSPAM@foni.net)

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: