Results 1 to 4 of 4
Thread: using printer device fonts
- 11-23-2010, 01:51 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
using printer device fonts
I have written a POS system which uses the SAM4s ellix 20 printer.
The problem is that receipts are printing far too light, i contacted the manufacturer and they said that i should use the device fonts rather than graphics based fonts.
Is there any way in java to
a) determine the type of font that the printer is using
b) print a line using the printers "device font"
thanks in advance
simo_mon
- 11-23-2010, 06:04 AM #2
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
ok i have a way to get printer attributes, but i still can't get anything like the
printers font ? any suggestions
Java Code:public void printAttrbutes(PrintService printService) { System.out.println("Printer Name is (" + printService.getName()+ ")" ); PrintServiceAttributeSet printServiceAttributeSet = printService.getAttributes(); Attribute[] array = printServiceAttributeSet.toArray(); System.out.println("PrinterLocation is (" + printServiceAttributeSet.get(PrinterLocation.class)); System.out.println("PrinterInfo is (" + printServiceAttributeSet.get(PrinterInfo.class)); System.out.println("PrinterState is (" + printServiceAttributeSet.get(PrinterState.class)); System.out.println("Destination is (" + printServiceAttributeSet.get(Destination.class)); System.out.println("PrinterMakeAndModel is (" + printServiceAttributeSet.get(PrinterMakeAndModel.class)); System.out.println("PrinterIsAcceptingJobs is (" + printServiceAttributeSet.get(PrinterIsAcceptingJobs.class)); System.out.println("PrinterIsAcceptingJobs is (" + printServiceAttributeSet.get(PrinterIsAcceptingJobs.class)); }
- 11-24-2010, 06:39 AM #3
Cross posted
using printer device fonts (Java in General forum at JavaRanch)
db
- 11-25-2010, 02:21 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
thanks for the heads up :) and sorry didn't occur to me that this was bad :)
everyone i "cross posted" this on the above link and i will cross post the solution.. once i get there :)
this is probably in the class of " your on your own with that one " so i'll put up what i got in case someone else is struggling :)
i worked out a way to communicate directly to the printer by sending stuff ( hex codes ) to COM1 BUT !!! this only works windows and on the machine that the printer is connected to :(
Java Code:code #1 public class PrintDriver { public static final int CR = 0x0D; public static final int PRINT_AND_LINE_FEED = 0x0A; public static void main(String [] args) { String com1 = "COM1"; try { FileWriter out = new FileWriter(com1); setCharacterSize(out); for(int i =0;i<5;i++) { out.write("1 Latte $3.50"); out.write(PRINT_AND_LINE_FEED); } lineFeed(out,10); setAutoCutter(out); out.close(); } catch (IOException e) { e.printStackTrace(); } } private static void setAutoCutter(FileWriter out) { if(out!=null) { try { out.write(0x1D); out.write(0x56); out.write(1); } catch(Exception e) { System.out.println(e.getMessage()); } } } private static void setCharacterSize(FileWriter out) { if(out!=null) { try { out.write(0x1D); out.write(0x21); out.write(1); } catch(Exception e) { System.out.println(e.getMessage()); } } } private static void lineFeed(FileWriter out, int numberOfLines) { if(out!=null) { try { for(int i =0;i<numberOfLines;i++) { out.write(PRINT_AND_LINE_FEED); } } catch(Exception e) { System.out.println(e.getMessage()); } } }
i have also worked out how to use the java printing stuff so that it uses the "printer defined font"
Java Code:code #2 public static void main(String [] args) { System.out.println(" PrintDriver"); PrintService defaultprinter = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = defaultprinter.createPrintJob(); DocFlavor flavour = DocFlavor.BYTE_ARRAY.AUTOSENSE; String message = "hello\n"; byte[] b = message.getBytes(); Doc doc = new SimpleDoc( b, flavour, null); try { job.print(doc, null); } catch (PrintException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
so the above code will use the default font for the printer, which is the "DocFlavor.BYTE_ARRAY.AUTOSENSE" part....
what i am trying to do now is combine part1 code with part2 code...
ie i am trying to send hex values to the printer using code like part2
Iv'e got a really ugly solution which is using an rmi server to call com1 on the correct machine but i want to try to avoid using it ???
any help or insight would be appreciated :
thanks again
and sorry for the un announced cross posting !
Similar Threads
-
Images, Device dependent? Can they be device independent?
By Markgm in forum AWT / SwingReplies: 20Last Post: 11-23-2010, 01:21 AM -
Fonts (Changing Fonts and Color's)
By dbashby in forum New To JavaReplies: 10Last Post: 04-06-2009, 01:32 AM -
How to change paper source or printer tray of a printer in java code
By JAVA_ER in forum Advanced JavaReplies: 2Last Post: 02-20-2009, 07:25 AM -
Specifying a Network Printer in Printer Servlet
By shapez in forum New To JavaReplies: 0Last Post: 03-06-2008, 03:21 PM -
please help on java program for printer : this printer is connected to system which
By for453 in forum Java 2DReplies: 0Last Post: 08-09-2007, 06:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks