Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kent Hamilton   on Dec 05 In Java Category.

  
Question Answered By: Calvin Banks   on Dec 05

Hello could you please help me with java  printing? This is my code...
I used the Java API for printing. The problem is this code  doesnt
find the print  services. Any advice? thanks

import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;

public class PrintFoo
{

public static void main(String args[])
{
PrintFoo ps = new PrintFoo();
}
public PrintFoo()
{
try
{
FileInputStream textStream;
textStream=new FileInputStream("tobeprinted.txt");

if(textStream==null)
{
System.out.println("asdfsaf");
return;
}

DocFlavor flavor=DocFlavor.INPUT_STREAM.POSTSCRIPT;
Doc mydoc=new SimpleDoc(textStream,flavor,null);
PrintRequestAttributeSet aset=new HashPrintRequestAttributeSet();
aset.add(new Copies(2));

PrintService[]services=PrintServiceLookup.lookupPrintServices(flavor,aset);
System.out.println(services.length);

if(services.length>0)
{
DocPrintJob job=services[0].createPrintJob();
try
{
job.print(mydoc,aset);
}
catch(PrintException pe)
{
System.err.println(pe);
}
}
}
catch(Exception ee)
{
System.err.println(ee);
}
}
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Java Printing Or get search suggestion and latest updates.


Tagged: