Thermal Printing in java using DocFlavor

1.5k views Asked by At

I am new to DocFlavor java . Anyone please help to start like I have simple text file and want to print on thermal printer ,which will be suitable DocFlavor type ?

1

There are 1 answers

8
Orvil Nordström On

It depends...If you want to print from a txt file then AUTO_SENSE or PostScript are ussually good ideas.

DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;

or DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;

Here is a Snippet as an example.

    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    FileInputStream in = new FileInputStream(new File("C:*PATH_TO_STRING_HERE"));

    PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));        
    flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc doc = new SimpleDoc(in, flavor, null);

    DocPrintJob job = service.createPrintJob();
    PrintJobWatcher pjw = new PrintJobWatcher(job);
    job.print(doc, pras);

I got this code when i was trying to figure out how to use my thermal receipt printer...If you want a more thourough explanation. IF you need a more in depth answer...

Then go here !

NOTE if you need to print out charactesr such as ä, ö or å then this will propably not work well as they will be obscured... I do not know how to print out special characters.

Sincerly...

//Orville

For more info on docflavors..

Go here !