Printing text file in java?This document does not conform to the Adobe Document Structuring Conventions and may not print correctly -
i have written below code in java printing simple text file,
import java.io.fileinputstream; import java.io.ioexception; import javax.print.doc; import javax.print.docflavor; import javax.print.docprintjob; import javax.print.printexception; import javax.print.printservice; import javax.print.printservicelookup; import javax.print.simpledoc; import javax.print.attribute.hashprintrequestattributeset; import javax.print.attribute.printrequestattributeset; import javax.print.attribute.standard.copies; public class printimage { static public void main(string args[]) throws exception { try { printrequestattributeset pras = new hashprintrequestattributeset(); pras.add(new copies(1)); /* printservice pss[] = printservicelookup.lookupprintservices(docflavor.input_stream.text_plain_us_ascii.autosense, pras); if (pss.length == 0) throw new runtimeexception("no printer services available.");*/ printservice ps = printservicelookup.lookupdefaultprintservice(); system.out.println("printing " + ps); docprintjob job = ps.createprintjob(); fileinputstream fin = new fileinputstream("test.txt"); doc doc = new simpledoc(fin, docflavor.input_stream.text_plain_us_ascii.autosense, null); job.print(doc, pras); fin.close(); } catch (ioexception ie) { ie.printstacktrace(); system.out.println(ie.tostring()); } catch (printexception pe) { system.out.println(pe.tostring()); pe.printstacktrace(); } } }
i using red hat enterprise server 6.0 jdk1.6.0_43 development platform.the code executed without errors.and have verified in cups job queued in printer queue.but printer not printing job.i got following error in cups log,
w [18/apr/2013:15:09:24 +0530] [job 15] document not conform adobe document structuring conventions , may not print correctly!
but same program works pdf files under rhel6.0.only txt,doc files not printing.
one more thing same code working under ubuntu 12.04 , rhel4.7. rhel6.0 pdf file printing.
please me problem solved...
Comments
Post a Comment