what DocFlavor shall I use when I want to print string?
Here is some of my code :
java.lang.String printStr = new String("222222222222222222");
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
Doc doc = new SimpleDoc(printStr, flavor, das);
when I run this code , the following error occured:
Error 500--Internal Server Error
java.lang.IllegalArgumentException: data is not of declared type
at javax.print.SimpleDoc.(SimpleDoc.java:82)
this means I chose a wrong DocFlavor,
what DocFlavor sould I use , please give me valuable suggestions, Thanks a lot.
here is my code :
java.lang.StringprintStr = new String("222222222222222222");
if (printStr != null && printStr.length() > 0)
{
int PAGES = 1;
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(printStr, flavor, das);
job.print(doc, pras);
}
Please tell me how to solve this problem!
Thank you
The DOC_FLAVOR you should use is one that's supported by your printer. It's not determined just by what you're printing, it's the destination, too.
Try DocFlavor.INPUT_STREAM.AUTOSENSE.
You'll want to read this, too:
http://www-106.ibm.com/developerworks/java/library/j-mer0322/
http://www-106.ibm.com/developerworks/java/library/j-mer0424.html
%