Printing problem

M

Mika Suomi

I have tried to print a text file and I have read articles from java.sun -
pages and there is an example which tell you to use in flavor
TEXT_PLAIN_TEXT but when I try to compile it I got this message:

DocFlavor.INPUT_STREAM.TEXT_PLAIN_TEXT cannot be resolved

And I have tried to use other options but bad result no printing I put the
code I use in here maybe somebody could help me.



import java.io.FileInputStream;

import java.io.FileNotFoundException;

import javax.print.*;

import javax.print.attribute.*;

import javax.print.attribute.standard.*;



public class PrintToPaper {


private FileInputStream texti;


public PrintToPaper()

{


}

public void Print(){


try{

text=new FileInputStream("G:\\Work\\Java\\TEST.txt");

}

catch(FileNotFoundException e){

}

if(text==null){

return;

}

DocFlavor myFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;

Doc MyDoc = new SimpleDoc(text, myFormat, null);

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

aset.add(new Copies(1));

aset.add(MediaSizeName.ISO_A4);

aset.add(Sides.ONE_SIDED);

PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();

DocPrintJob job = pservice.createPrintJob();

try {

job.print(MyDoc,aset);

}


catch (PrintException e) {

System.err.println(e);

}

}

}
 
R

Ricardo

Mika said:
I have tried to print a text file and I have read articles from java.sun -
pages and there is an example which tell you to use in flavor
TEXT_PLAIN_TEXT but when I try to compile it I got this message:

DocFlavor.INPUT_STREAM.TEXT_PLAIN_TEXT cannot be resolved

Without examining the code (for now), did you try
DocFlavor.INPUT_STREAM.AUTOSENSE ?
 
M

Markku

Mika said:
I have tried to print a text file and I have read articles from java.sun -
pages and there is an example which tell you to use in flavor
TEXT_PLAIN_TEXT but when I try to compile it I got this message:

DocFlavor.INPUT_STREAM.TEXT_PLAIN_TEXT cannot be resolved

And I have tried to use other options but bad result no printing I put the
code I use in here maybe somebody could help me.

In DocFlavor there is no such as .INPUT_STREAM.TEXT_PLAIN_TEXT.

I copy and compile your code and it works just fine.
Do you know in which format your text is?

These are found in INPUT_STREAM
..TEXT_PLAIN_US_ASCII
..TEXT_PLAIN_UTF_8
..TEXT_PLAIN_UTF_16
..TEXT_PLAIN_UTF_16BE
..TEXT_PLAIN_UTF_16LE
..TEXT_PLAIN_HOST
And then there is AUTOSENSE (as Ricardo mentioned earlier).

- Markku -
 
M

Markku

Mika said:
My mistake about that TEXT_PLAIN_TEXT but in the java'a page here is address
http://java.sun.com/j2se/1.4.2/docs/guide/jps/spec/jpsOverview.fm4.html
in code there is TEXT_PLAIN_ASCII what I try first.
But I have tried all the options none of them work.
I put image file to replace test.txt and GIF to DocFlavor and that work
Textfile is written by windows notepad .
I use eclipse to write and compile.

Notepad is dangerous nowadays :) It understand UTF-8, UTF-16 and
even Unicode text (check the Save As dialog options). You file
maybe isn't ASCII at all.

By the way, did you try AUTOSENSE option?
 
M

Mika Suomi

As I say earlier it prints image when I use GIF,JPG .

When I use AUTOSENSE it doesn't give any error message and it do the job
even the file is image or something else but nothing comes out from printer.

When I save the textfile as UTF-8 encoding and change AUTOSENSE to
TEXT_PLAIN_UTF_8 it gives error:
sun.print.PrintJobFlavorException: invalid flavor



Mika Suomi
 
R

Ricardo

Mika said:
As I say earlier it prints image when I use GIF,JPG .

When I use AUTOSENSE it doesn't give any error message and it do the job
even the file is image or something else but nothing comes out from printer.

When I save the textfile as UTF-8 encoding and change AUTOSENSE to
TEXT_PLAIN_UTF_8 it gives error:
sun.print.PrintJobFlavorException: invalid flavor



Mika Suomi

This is going to help you:

http://www.javaalmanac.com/egs/javax.print/BasicPrint.html?l=find
http://www.javaalmanac.com/egs/javax.print/WaitForDone.html
 
Joined
Oct 15, 2006
Messages
1
Reaction score
0
Hi,

Did you get this working?
I have the same problem. I am printing to a printer but although the printer recognises I have sent a job it does not produce anything.

The datatype of the print job is "RAW", I dont know what I am doing wrong?????

Khev..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top