Results 1 to 4 of 4
  1. #1
    simo_mon is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default 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

  2. #2
    simo_mon is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    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));
    			
    		
    		
    	}

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

  4. #4
    simo_mon is offline Member
    Join Date
    Dec 2008
    Posts
    50
    Rep Power
    0

    Default

    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

  1. Replies: 20
    Last Post: 11-23-2010, 01:21 AM
  2. Fonts (Changing Fonts and Color's)
    By dbashby in forum New To Java
    Replies: 10
    Last Post: 04-06-2009, 01:32 AM
  3. Replies: 2
    Last Post: 02-20-2009, 07:25 AM
  4. Specifying a Network Printer in Printer Servlet
    By shapez in forum New To Java
    Replies: 0
    Last Post: 03-06-2008, 03:21 PM
  5. Replies: 0
    Last Post: 08-09-2007, 06:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •