I have the problem that when you are in windows and you try to print through JAVA you can only use the AUTOSENSE property.
However my string that I want to get printed is in greek => UTF-8. When I turn the AUTOSENSE to TEXT_PLAIN_UTF8 i get an: sun.print.PrintJobFlavorException: invalid flavor exception….
Any suggestions? Or other way of printing in Unicode?
thanks!
String datastr = "UNICODE STRING";
byte[] databa = null;
try {
databa = datastr.getBytes("UTF8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
DocFlavor docFlavor = DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
if (databa != null) {
DocPrintJob pjob = service.createPrintJob();
Doc doc = new SimpleDoc(databa, docFlavor, null);
try {
pjob.print(doc, aset);
} catch (PrintException e) {
e.printStackTrace();
}
if i try to print it in STRING.TEXT_PLAIN and also in everything else than AUTOSENSE, i get this:
sun.print.PrintJobFlavorException: invalid flavor
at sun.print.Win32PrintJob.print(Unknown Source)
Finally the supported Flavors are these…
Win32 Printer : HP Deskjet 5440 Series Flavors:
image/gif; class="[B"
image/gif; class="java.io.InputStream"
image/gif; class="java.net.URL"
image/jpeg; class="[B"
image/jpeg; class="java.io.InputStream"
image/jpeg; class="java.net.URL"
image/png; class="[B"
image/png; class="java.io.InputStream"
image/png; class="java.net.URL"
application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
application/octet-stream; class="[B"
application/octet-stream; class="java.net.URL"
application/octet-stream; class="java.io.InputStream"
Its easier to do it with SWT here is the code…