Printing from Swing

Discussion in 'Java' started by Shaun Donovan, Oct 1, 2004.

  1. Hello all.

    I am new to Java and have a problem when trying to print to an A5 page.
    I would like my application to set the default page size and margins
    without going through a pageDialog. I have tried to set the pageFormat
    and Paper, but if I don't send it through the pageDialog, the sizes are
    ignored and the defaults are applied. Here is a snippet of the code that
    I have tried. I would like to remove the pf = printJob.pageDialog(pf)
    line. Am I missing something?

    {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat pf = printJob.defaultPage();
    Paper pap = pf.getPaper();
    pap.setSize(420, 597); //A5
    pap.setImageableArea(36, 36, 348, 525); //Margins at 0.5in
    pf.setPaper(pap);
    pf = printJob.pageDialog(pf);
    printJob.setPrintable(this, pf);
    if (printJob.printDialog())
    {
    try
    {
    printJob.print();
    } catch (Exception ex)
    {
    ex.printStackTrace();
    }
    }
    }
    Shaun Donovan, Oct 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    491
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    663
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,753
    lizard
    Jan 30, 2006
  4. S.T
    Replies:
    2
    Views:
    568
  5. Knute Johnson

    Swing is dead! Long live Swing.

    Knute Johnson, Feb 16, 2012, in forum: Java
    Replies:
    32
    Views:
    3,731
    Daniel Pitts
    Feb 29, 2012
Loading...

Share This Page