Landscape

Discussion in 'Java' started by freesoft_2000, Jul 12, 2006.

  1. Hi everyone,

    I am trying to print a landscape paper using J2SE SDK
    1.5.0_06 with the native print dialog(windows in my case). When i print in
    portrait the printout is perfect but when print in landscape the printout
    simpley does not rotate but just shifts downwards.

    The thing is that this problem does not occur in 1.4,
    but only in 1.5. Could this be a bug or have i done something wrong in the
    code.

    Here is a very simple compilable example using one of sun's examples. As
    you can see setting the pageformat to portrait the printout is correct but
    when seeting the page format to landscape it does not rotate but simple
    shift downwards.

    Here is the program

    import java.awt.*;
    import java.awt.print.*;

    public class PrintBook {
    public static void main(String[] args) {

    // Get a PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();
    // Create a landscape page format
    PageFormat pfl = job.defaultPage();

    pfl.setOrientation(PageFormat.LANDSCAPE);
    //pfl.setOrientation(PageFormat.PORTRAIT);
    // Set up a book
    Book bk = new Book();
    bk.append(new PaintCover(), pfl);
    // Pass the book to the PrinterJob
    job.setPageable(bk, pf1);
    // Put up the dialog box
    if (job.printDialog()) {
    // Print the job if the user didn't cancel printing
    try { job.print(); }
    catch (Exception e) {e.printStackTrace();}
    }
    System.exit(0);
    }
    }

    class PaintCover implements Printable {
    Font fnt = new Font("Helvetica-Bold", Font.PLAIN, 72);

    public int print(Graphics g, PageFormat pf, int pageIndex)
    throws PrinterException {
    g.setFont(fnt);
    g.setColor(Color.black);
    int yc = (int) (pf.getImageableY() +
    pf.getImageableHeight()/2);
    g.drawString("Widgets, Inc.", 72, yc+36);
    return Printable.PAGE_EXISTS;
    }
    }

    When i run the above program in 1.4 there are no problems, could this be a
    bug in 1.5.0_06?

    Any help i greatly appreciated

    Thank You

    Yours Sincerely

    Richard West
     
    freesoft_2000, Jul 12, 2006
    #1
    1. Advertising

  2. freesoft_2000

    Andrew T. Guest

    freesoft_2000 wrote:
    ....
    > When i run the above program ..


    I was unable to compile the above program..

    F:\....\PrintBook.java:21: cannot find symbol
    symbol : variable pf1
    location: class PrintBook
    job.setPageable(bk, pf1);

    Andrew T.
     
    Andrew T., Jul 12, 2006
    #2
    1. Advertising

  3. Hi everyone,

    There seems to be a careless mistake in the above program at
    the below line

    job.setPageable(bk, pfl);

    simply change it to

    job.setPageable(bk);

    so that it can now compile but please note that the problem of printing in
    landscape on this version of java is still having the problem

    Richard West
     
    freesoft_2000, Jul 13, 2006
    #3
  4. Hi everyone,

    When i use the code to print to a file or to a print preview
    the output is correct but only when i print out to paper then the error
    occurs. But this error only seems to occur on 1.5.0_06 but not on 1.4.

    Should file this as a bug because i really doubt its my fault because it
    works on version of Java and not another.

    Any comments guys

    Richard West
     
    freesoft_2000, Jul 14, 2006
    #4
  5. freesoft_2000 wrote:
    > Hi everyone,
    >
    > When i use the code to print to a file or to a print preview
    > the output is correct but only when i print out to paper then the error
    > occurs. But this error only seems to occur on 1.5.0_06 but not on 1.4.
    >
    > Should file this as a bug because i really doubt its my fault because it
    > works on version of Java and not another.
    >
    > Any comments guys


    Everything I've ever heard of the Java print API, combined
    with your test results, suggests that it is a bug to me.

    Andrew T.
     
    Andrew Thompson, Jul 14, 2006
    #5
  6. freesoft_2000

    Chris Uppal Guest

    freesoft_2000 wrote:

    > When i use the code to print to a file or to a print preview
    > the output is correct but only when i print out to paper then the error
    > occurs. But this error only seems to occur on 1.5.0_06 but not on 1.4.


    You may have a print driver problem too. I just tried it on my real printer
    (having persuaded it to start working well enough to see the output), and your
    code produces landscape output with both 1.4 and 1.5 JVMs[*]. I've taken a
    look at the native JNI code which 1.4 and 1.5 use to drive the MS printing, and
    I can't see any differences which might be suspected to have this effect.
    However MS printing is pretty bloody arcane, and so is Java's print API come to
    that, so I could be missing something.

    ([*] I'm using an Epson "Stylus color 760" printer with the MS-supplied print
    driver rather than the stupidly over-complicated crap which Epson attempt to
    foist on you.)

    -- chris
     
    Chris Uppal, Jul 15, 2006
    #6
    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. Dexter
    Replies:
    0
    Views:
    455
    Dexter
    Oct 18, 2004
  2. Eric

    ASP.net and Printing Landscape

    Eric, May 31, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    8,917
    Tim McOwan
    May 31, 2005
  3. =?Utf-8?B?THluZXJz?=

    Crystal Report to Excel in Landscape

    =?Utf-8?B?THluZXJz?=, Dec 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    =?Utf-8?B?THluZXJz?=
    Dec 12, 2005
  4. BlueSky

    Print in Landscape mode

    BlueSky, Jan 5, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,850
    BlueSky
    Jan 5, 2006
  5. Ralf
    Replies:
    2
    Views:
    11,238
    =?Utf-8?B?RWx0b24gVw==?=
    Feb 10, 2006
Loading...

Share This Page