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
Andrew T. - 12 Jul 2006 17:16 GMT
...
> 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.
freesoft_2000 - 13 Jul 2006 14:20 GMT
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
Andrew T. - 13 Jul 2006 15:42 GMT
...
> job.setPageable(bk, pfl);
>
> simply change it to
>
> job.setPageable(bk);
Yep, that compiles, and.. oops!
I thought I could look at the problem once the code was
runnable (even without an actual printer) but my vague recollection
of a 'preview' in the printdialog let me down.
> 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
OK. I went on a (quite unsuccessful) search of the bug database,
which was either returning 43000+ hits for some queries, and none
for others. Then I dumped the Bug D/B search and went to Google
to uncover just these that mention PrinterJob, 1.5 and landscape.
<http://www.google.com.au/search?as_q=PrinterJob+1.5+landscape&as_sitesearch=bugs
.sun.com>
It is only 7 hits, and none of them seem immediately relevant
to the problem.
That's me out of ideas, sorry..
Andrew T.
Chris Uppal - 13 Jul 2006 17:11 GMT
> 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
[quoted text clipped - 4 lines]
> but only in 1.5. Could this be a bug or have i done something wrong in the
> code.
Your code (with your later amendment) works correctly for me. That's using jdk
1.5.0_6 over WinXP. That suggests that your code is OK, and if there's a
problem anywhere it's in the printer driver and/or Sun's code.
I'm actually printing to a "PostScript" printer set to print to file, rather
than an actual paper-and-ink-consumer, which may make a difference. I'm
selecting that pseudo-printer from the print dialog, so it's not my default
printer. That might make a difference.
-- chris
freesoft_2000 - 14 Jul 2006 19:58 GMT
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
Andrew Thompson - 14 Jul 2006 20:36 GMT
> Hi everyone,
>
[quoted text clipped - 6 lines]
>
> 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.
Chris Uppal - 15 Jul 2006 10:33 GMT
> 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