Landscape

F

freesoft_2000

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
 
A

Andrew T.

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.
 
F

freesoft_2000

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
 
F

freesoft_2000

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
 
A

Andrew Thompson

freesoft_2000 said:
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.
 
C

Chris Uppal

freesoft_2000 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top