Sashanak Mohanty

Greenhorn
+ Follow
since Mar 11, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sashanak Mohanty

Hello ,
I am working on a project where the printer will be given multiple files to print in a sequence .But the problem is the printer is taking the first file to print. By the time the second file is sent to print while the first print operation is not complete. I want to send the next print sequentially once the first print job completes or canceled i.e the printJob is idle to accept the new print call.
The exception throws is ...
javax.print.PrintException: already printing
The following code is for referal.
Please Help me ..I am in deadline.
Thank you.
===============
printmulti.java
===============
import javax.print.*;
import javax.print.event.*;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.print.attribute.EnumSyntax.*;
import javax.print.attribute.standard.*;
import javax.print.DocPrintJob;
import javax.print.attribute.*;
import javax.print.DocFlavor;
import java.lang.*;
import java.io.*;
public class printmulti
{
static DocFlavor flavor;
static PrintService pr_service;
static DocPrintJob job;
public static void main(String []arg)
{
printmulti prn=new printmulti();
flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
pr_service= PrintServiceLookup.lookupDefaultPrintService();
job = pr_service.createPrintJob();
for(int i=0;i<arg.length;i++)
{
prn.print(arg[i]);
}
}
void print(String filename)
{
try
{
// Open the file
InputStream is = new BufferedInputStream(new FileInputStream(filename));
// Create the print job
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Doc doc = new SimpleDoc(is,flavor ,null);
// Monitor print job events
PrintJobWatcher pjDone = new PrintJobWatcher(job);
// Print it
job.print(doc, aset);
// Wait for the print job to be done
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
}
catch (PrintException e)
{
System.out.println("Print Exception =========\n : "+e);
}
catch (IOException e)
{
System.out.println("IO Exception =========\n : "+e);
}
}
}
class PrintJobWatcher
{
// true iff it is safe to close the print job's input stream
boolean done = false;
PrintJobWatcher(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
allDone();
}
public void printJobCompleted(PrintJobEvent pje) {
allDone();
}
public void printJobFailed(PrintJobEvent pje) {
allDone();
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
allDone();
}
void allDone() {
synchronized (PrintJobWatcher.this) {
done = true;
PrintJobWatcher.this.notify();
}
}
});
}
public synchronized void waitForDone()
{
try
{
while (!done)
{
System.out.println("Waiting");
wait();
}
} catch (InterruptedException e)
{
}
}
}
20 years ago
Hello ,
I am working on a project where the printer will be given multiple files to print. The files will be sent in a sequence. But the problem is the printer is taking the first file to print. By the time the second file is sent to print while the first print operation is not complete. I want to send the next print sequentially once the first print job completes or canceled i.e the printJob is idle to accept the new print call.
The exception throws is ...
javax.print.PrintException: already printing
The following code is for referal.
Please Help me ..I am in deadline.
Thank you.
===============
printmulti.java
===============
import javax.print.*;
import javax.print.event.*;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.print.attribute.EnumSyntax.*;
import javax.print.attribute.standard.*;
import javax.print.DocPrintJob;
import javax.print.attribute.*;
import javax.print.DocFlavor;
import java.lang.*;
import java.io.*;
public class printmulti
{
static DocFlavor flavor;
static PrintService pr_service;
static DocPrintJob job;
public static void main(String []arg)
{
printmulti prn=new printmulti();
flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
pr_service= PrintServiceLookup.lookupDefaultPrintService();
job = pr_service.createPrintJob();
for(int i=0;i<arg.length;i++)
{
prn.print(arg[i]);
}
}
void print(String filename)
{
try
{
// Open the file
InputStream is = new BufferedInputStream(new FileInputStream(filename));
// Create the print job
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Doc doc = new SimpleDoc(is,flavor ,null);
// Monitor print job events
PrintJobWatcher pjDone = new PrintJobWatcher(job);
// Print it
job.print(doc, aset);
// Wait for the print job to be done
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
}
catch (PrintException e)
{
System.out.println("Print Exception =========\n : "+e);
}
catch (IOException e)
{
System.out.println("IO Exception =========\n : "+e);
}
}
}
class PrintJobWatcher
{
// true iff it is safe to close the print job's input stream
boolean done = false;
PrintJobWatcher(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {
public void printJobCanceled(PrintJobEvent pje) {
allDone();
}
public void printJobCompleted(PrintJobEvent pje) {
allDone();
}
public void printJobFailed(PrintJobEvent pje) {
allDone();
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
allDone();
}
void allDone() {
synchronized (PrintJobWatcher.this) {
done = true;
PrintJobWatcher.this.notify();
}
}
});
}
public synchronized void waitForDone()
{
try
{
while (!done)
{
System.out.println("Waiting");
wait();
}
} catch (InterruptedException e)
{
}
}
}
20 years ago