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