D
Dexter
Hi, I need a bit of help. I got this class from SunSoft's online
documentation to which I made slight changes. I am trying to print a
the contents of a text file (the file containing the code). It
compiles correct. When I execute it, it shows me the printer dialog
box suggesting that its sending the output to printer yet nothing gets
printed.
Can someone suggest what is it thats wrong with this code
==============================
BasicStream.java
==============================
import java.io.*;
import javax.print.*;
import javax.print.event.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class BasicStream {
public static void main(String[] args) {
String filename = "BasicStream.java";
BasicStream bs = new BasicStream();
bs.printme(filename);
}
public void printme(String filename){
try {
PrintService
defaultService=PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(new Copies(1));
PrintService[] pservices
=PrintServiceLookup.lookupPrintServices(flavor, aset);
PrintService service = ServiceUI.printDialog(null, 50, 50,pservices,
defaultService, null,aset);
if (pservices!=null)
{
DocFlavor[] flavs=service.getSupportedDocFlavors();
if (flavs.length==0)
System.out.println("No Flavors supported!!!");
for (int i=0; i<flavs.length; i++)
{
System.out.println(flavs.getMimeType() + "-->"+
flavs.getRepresentationClassName());
}
}
if (pservices.length > 0) {
System.out.println("selected printer: " +pservices[0].getName());
DocPrintJob pj = pservices[0].createPrintJob();
/* * Create a Doc object to hold the print data.
* Since the data is postscript located in a disk file,
* an input stream needs to be obtained
* BasicDoc is a useful implementation that will if
* requested close the stream when printing is completed.
*/
FileInputStream fis = new FileInputStream(filename);
Doc doc = new SimpleDoc(fis, flavor, null);
/* print the doc as specified
*/
pj.print(doc, aset);
}
else
System.out.println("Selected Printers: "+pservices.length);
}
catch (PrintException e) {
System.out.println("Print Error: " + e.getMessage());
}
catch (IOException e) {
System.out.println("IO Error: " + e.getMessage());
}
}
}
=====================================
documentation to which I made slight changes. I am trying to print a
the contents of a text file (the file containing the code). It
compiles correct. When I execute it, it shows me the printer dialog
box suggesting that its sending the output to printer yet nothing gets
printed.
Can someone suggest what is it thats wrong with this code
==============================
BasicStream.java
==============================
import java.io.*;
import javax.print.*;
import javax.print.event.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class BasicStream {
public static void main(String[] args) {
String filename = "BasicStream.java";
BasicStream bs = new BasicStream();
bs.printme(filename);
}
public void printme(String filename){
try {
PrintService
defaultService=PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(new Copies(1));
PrintService[] pservices
=PrintServiceLookup.lookupPrintServices(flavor, aset);
PrintService service = ServiceUI.printDialog(null, 50, 50,pservices,
defaultService, null,aset);
if (pservices!=null)
{
DocFlavor[] flavs=service.getSupportedDocFlavors();
if (flavs.length==0)
System.out.println("No Flavors supported!!!");
for (int i=0; i<flavs.length; i++)
{
System.out.println(flavs.getMimeType() + "-->"+
flavs.getRepresentationClassName());
}
}
if (pservices.length > 0) {
System.out.println("selected printer: " +pservices[0].getName());
DocPrintJob pj = pservices[0].createPrintJob();
/* * Create a Doc object to hold the print data.
* Since the data is postscript located in a disk file,
* an input stream needs to be obtained
* BasicDoc is a useful implementation that will if
* requested close the stream when printing is completed.
*/
FileInputStream fis = new FileInputStream(filename);
Doc doc = new SimpleDoc(fis, flavor, null);
/* print the doc as specified
*/
pj.print(doc, aset);
}
else
System.out.println("Selected Printers: "+pservices.length);
}
catch (PrintException e) {
System.out.println("Print Error: " + e.getMessage());
}
catch (IOException e) {
System.out.println("IO Error: " + e.getMessage());
}
}
}
=====================================