Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Landscape

Reply
Thread Tools

Landscape

 
 
freesoft_2000
Guest
Posts: n/a
 
      07-12-2006
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

 
Reply With Quote
 
 
 
 
Andrew T.
Guest
Posts: n/a
 
      07-12-2006

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.

 
Reply With Quote
 
 
 
 
freesoft_2000
Guest
Posts: n/a
 
      07-13-2006
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

 
Reply With Quote
 
freesoft_2000
Guest
Posts: n/a
 
      07-14-2006
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

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      07-14-2006
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.

 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      07-15-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
crystal report viewer in landscape Ralf ASP .Net 2 02-10-2006 06:40 PM
Print in Landscape mode BlueSky ASP .Net 0 01-05-2006 09:04 PM
Crystal Report to Excel in Landscape =?Utf-8?B?THluZXJz?= ASP .Net 0 12-12-2005 06:27 PM
ASP.net and Printing Landscape Eric ASP .Net 4 05-31-2005 04:24 PM
How to configure a page to print in the landscape format? Dexter ASP .Net 0 10-18-2004 07:47 PM



Advertisments