Results 1 to 2 of 2

Thread: java printing

  1. #1
    smatboy is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Post java printing

    i want to know about printing in POS printer . but i dont want to run print setup

    i wrote this code



    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.print.*;

    public class Printer implements Printable, ActionListener {


    public int print(Graphics il, PageFormat pf, int page) throws
    PrinterException {

    if (page > 0) {
    return NO_SUCH_PAGE;
    }



    Graphics2D g2d = (Graphics2D)il;
    g2d.translate(pf.getImageableX(), pf.getImageableY());


    il.drawString("Chocholate", 100, 100);


    return PAGE_EXISTS;
    }

    public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    boolean ok = job.printDialog();
    if (ok) {
    try {
    job.print();
    } catch (PrinterException ex) {

    }
    }
    }

    public static void main(String args[]) {


    JFrame fr = new JFrame(" Printer");
    fr.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    });
    JButton printButton = new JButton("Print");
    printButton.addActionListener(new Printer());
    fr.add("Center", printButton);
    fr.pack();
    fr.setVisible(true);
    }
    }

    here i can get print but the print setup run
    ex
    *******Shop name********
    2012/12/01

    chocalate 1 1$




    total 1$

    i want to print a bill like this pls help me thnx
    Last edited by smatboy; 01-05-2013 at 07:15 AM.

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: java printing

    press edit key to insert problem description and code and formulate your problem correctly:

    I like likes!

Similar Threads

  1. java printing
    By makasoft in forum New To Java
    Replies: 1
    Last Post: 05-19-2012, 02:27 AM
  2. Replies: 0
    Last Post: 12-26-2011, 04:52 PM
  3. Replies: 9
    Last Post: 08-19-2011, 01:59 AM
  4. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 10:17 AM
  5. [Java Printing]
    By remnahush in forum Advanced Java
    Replies: 1
    Last Post: 11-08-2007, 04:28 PM

Posting Permissions

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