3 Replies - 617 Views - Last Post: 17 February 2015 - 07:38 AM Rate Topic: -----

#1 mehtabkhna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-February 15

thermal printing

Posted 17 February 2015 - 05:58 AM

please help i m new to Swing and i m unable to print all the contains to thermal printer page using this code
this code start printing from the middle of page.
public int print(Graphics g, PageFormat pf, int page) throws
	PrinterException {

		if (page > 0) { /* We have only one page, and 'page' is zero-based */
			return NO_SUCH_PAGE;
		}

		/* User (0,0) is typically outside the imageable area, so we must
		 * translate by the X and Y values in the PageFormat to avoid clipping
		 */
		Graphics2D g2d = (Graphics2D)g;
//		g2d.translate(pf.getImageableX(), pf.getImageableY());
		g2d.translate(pf.getImageableX(), pf.getImageableY());

		/* Now we perform our rendering */
		
		String title = l1.getText();
		System.out.println("title " + title);
		
		String title1 = l0.getText().toString();
		String title2 = l01.getText().toString();
		
		String plazaname = l2.getText().toString();
		String plazaedit = tf1.getText().toString();
		
		String ticketno = l3.getText().toString();
		String ticketnoedit = tf2.getText().toString();
		
		String date = l4.getText().toString();
		String dateedit = tf3.getText().toString();
		
		String time = l5.getText().toString();
		String timeedit = tf4.getText().toString();
		
		String shift = l6.getText().toString();
		String shiftedit = tf5.getText().toString();
		
		String booth = l7.getText().toString();
		String boothedit = tf6.getText().toString();
		
		String user = l8.getText().toString();
		String useredit = tf7.getText().toString();
		
		String vehicleclass = l9.getText().toString();
		String vehicleclassedit = tf8.getText().toString();
		
		String paymentmode = l10.getText().toString();
		String paymentmodeedit = tf9.getText().toString();
		
		String vehicleno = l11.getText().toString();
		String vehiclenoedit = tf10.getText().toString();
		
		String tollfare = l12.getText().toString();
		String tollfareedit = tf11.getText().toString();
		
		String helpline = l13.getText().toString();
		
		String wishhappy = l14.getText().toString();
		
//		g.drawString("Hello world!", 100, 100);
		
		//g.setFont(new Font("Garamond", Font.LAYOUT_NO_LIMIT_CONTEXT, 20));
		//g.setFont(new Font("Garamond", Font.ROMAN_BASELINE, 10));
		g.drawString(title, 50, 10);
		g.drawString(title1, 50, 25);
		g.drawString(title2, 50, 40);
		
		g.setColor(Color.lightGray);
		g.drawString(plazaname, 50,80);
		g.drawString(plazaedit, 150, 80);
		
		g.drawString(ticketno, 50, 95);
		g.drawString(ticketnoedit, 150, 95);
		
		g.drawString(date, 50, 110);
		g.setColor(Color.BLACK);
		g.drawString(dateedit, 150, 110);
		
		g.setColor(Color.lightGray);
		g.drawString(time, 50, 125);
		
		g.setColor(Color.BLACK);
		g.drawString(timeedit, 150, 125);
		
		g.setColor(Color.lightGray);
		g.drawString(shift, 50, 140);
		g.drawString(shiftedit, 150, 140);
		
		g.drawString(booth, 50, 155);
		g.drawString(boothedit, 150, 155);
		
		g.drawString(user, 50, 170);
		g.drawString(useredit, 150, 170);
		
		g.drawString(vehicleclass, 50, 185);
		
		g.setColor(Color.BLACK);
		g.drawString(vehicleclassedit, 155, 185);
		
		g.setColor(Color.lightGray);
		g.drawString(paymentmode, 50, 200);
		
		g.setColor(Color.BLACK);
		g.drawString(paymentmodeedit, 155, 200);
		
		g.setColor(Color.lightGray);
		g.drawString(vehicleno, 50, 215);
		
		g.setColor(Color.BLACK);
		g.drawString(vehiclenoedit, 150, 215);
		
		g.setColor(Color.lightGray);
		g.drawString(tollfare, 50, 230);
		
		g.setColor(Color.BLACK);
		g.drawString(tollfareedit, 150, 230);
		
		g.setColor(Color.lightGray);
		g.drawString(helpline, 50, 290);
		
		g.setColor(Color.BLACK);
		g.drawString(wishhappy, 50, 305);
		
		
		
		
				
		
		

		/* tell the caller that this page is part of the printed document */
		return PAGE_EXISTS;
	}


Is This A Good Question/Topic? 0
  • +

Replies To: thermal printing

#2 mehtabkhna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-February 15

Re: thermal printing

Posted 17 February 2015 - 06:22 AM

please help if anybody have any idea..
Thanks in advance.
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: thermal printing

Posted 17 February 2015 - 07:24 AM

Please post your questions in the appropriate forum. Tutorial section is not for help
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13768
  • View blog
  • Posts: 54,954
  • Joined: 12-June 08

Re: thermal printing

Posted 17 February 2015 - 07:38 AM

(Split off from: http://www.dreaminco...java-printing/)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1