tags:

views:

264

answers:

1

Hello, I have written code to run the printer programatically in Java.I have to set the value of docflavor to print the .txt file.When I set it for INPUT_STREAM.TEXT_PLAIN_UTF_8 and run my program on Linux , it prints the text file.but when i run the same code for windows.It can't print the text file.It only prints the jpeg format file.I am using HP Deskjet F735 printer for this. Following is my code .

            DocFlavor docflavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;

            PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();

            attr_set.add(new Copies(2));

  PrintService[] service = PrintServiceLookup.lookupPrintServices(docflavor, attr_set);

             if (service.length==0) {
                    JOptionPane.showMessageDialog(null, "No Printer Selected");
                }

            else if (service.length > 0) {
                System.out.println("Selected printer is " + service[0].getName());

                    DocPrintJob pj = service[0].createPrintJob();
                    {
                        PrintService ps = pj.getPrintService();
                        FileInputStream fis = null;
                        try {
                            File file = new File("/home/ignu/Desktop/newfile");
                            fis = new FileInputStream(file);
                            Doc doc = new SimpleDoc(fis, docflavor, null);
                            pj.print(doc, attr_set);
A: 

what does PrintService.getSupportedDocFlavors returns for you? Maybe UTF-8 is unsupported?

Edit:

"text/plain; charset=utf-8" seems to be unsupported. Try

DocFlavor docflavor = new DocFlavor.INPUT_STREAM ("application/octet-stream")

instead.

kaboom
attribute: color-supported attribute: printer-is-accepting-jobs attribute: queued-job-count attribute: printer-name flavor: image/gif; class="[B" flavor: image/gif; class="java.io.InputStream" flavor: image/gif; class="java.net.URL" flavor: image/jpeg; class="[B" flavor: image/jpeg; class="java.io.InputStream" flavor: image/jpeg; class="java.net.URL" flavor: application/octet-stream; class="[B" flavor: application/octet-stream; class="java.net.URL" flavor: application/octet-stream; class="java.io.InputStream"
om
Not working, I made change you have suggested,but still no printing activity.
om
It would be nice to see the same output on Linux. As far as I understand your Windows printer cannot print text files.
kaboom