Results 1 to 2 of 2

Thread: Printing

  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Printing

    Hi,

    I have a little problem with my code, and hopefully someone in here can see where I am goin wrong and point me in the right direction..

    Here is the code:

    Java Code:
    private void cmdPrintActionPerformed(java.awt.event.ActionEvent evt) {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((Printable) this);   
    boolean doPrint = printerJob.printDialog();
    PageFormat pf = printerJob.defaultPage();
    Paper paper   = pf.getPaper();
    paper.setImageableArea(2.0, 2.0, paper.getWidth(), paper.getHeight());
    pf.setPaper(paper);
    if(doPrint){    
    try {     
    printerJob.print();
    } catch (PrinterException ex) {     
    JOptionPane.showMessageDialog(null, ex.getMessage());  
    }   
    }
            
    this.dispose();
            
    }
    And this:

    Java Code:
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {  
    if (pageIndex > 0) {
    return(NO_SUCH_PAGE);
    } else {   
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    printPanel.print(g);
    return(PAGE_EXISTS);    
    }    
    }
    The thing is that I print the printPanel, and it doesn't fit the paper.
    That is what I want... I have tried a few things, but I am stuck...

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Printing

    Moved from Advanced Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 0
    Last Post: 12-26-2011, 03:52 PM
  2. Help in Printing
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2011, 03:40 PM
  3. Replies: 9
    Last Post: 08-19-2011, 12:59 AM
  4. Printing Job
    By qwerty53 in forum New To Java
    Replies: 2
    Last Post: 07-19-2011, 03:32 PM
  5. printing string backwards and printing every other
    By droidus in forum New To Java
    Replies: 22
    Last Post: 03-10-2011, 09:17 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
  •