-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
1.2.2
-
generic, x86
-
generic, windows_98, windows_nt
-
Verified
Name: tb29552 Date: 10/30/98
/*
I'm setting a pageformat of landscape.
However, it doesn't cause the printer
to print the page in landscape.
The page contents are in landscape but
the page is still in portrait.
here's a sample program.
*/
/*
Printing One Page with Graphics
Note that (0, 0) of the Graphics object is at the top-left of
the actual page, which is outside the printable area.
[EDITOR's NOTE: this is bug id 4179886]
In this example, the Graphics object is translated so that
(0, 0) becomes the top-left corner of the printable area.
*/
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
import javax.swing.*;
//
public class PrintGraphic extends JComponent implements Printable {
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
/* i */ drawGraphics(g2d, pf); /**/
return Printable.PAGE_EXISTS;
}
//
void drawGraphics(Graphics2D g, PageFormat pf) {
double x, y, iw, w, h, ih;
System.out.println(x = pf.getImageableX());
System.out.println(y = pf.getImageableY());
System.out.println(iw = pf.getImageableWidth());
System.out.println(ih = pf.getImageableHeight());
System.out.println(w = pf.getWidth());
System.out.println(h = pf.getHeight());
g.setColor(Color.black);
g.draw(new Ellipse2D.Double(0, 0, iw, ih));
g.drawString("Hello", 200, 200);
g.fillOval(0, 0, 100, 100);
}
//
public static void main(String[] args) {
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = pjob.defaultPage();
pf.setOrientation(PageFormat.LANDSCAPE);
pjob.setPrintable(new PrintGraphic (), pf);
try {
pjob.print();
} catch(Exception e) {
e.printStackTrace();
}
}
}
//
(Review ID: 41624)
======================================================================
Name: gsC80088 Date: 03/04/99
When printing to a PostScript printer, your Printable's print method is supplied with either a PSPathGraphics which generates "normal" PostScript or a ProxyGraphics2D which generates a gigantic image of the page. In the PSPathGraphics case, the Graphic2D doesn't have the correct page transform set.
To repeat:
1) Make a Printable which does a bit of line drawing.
2) Print.
3) Print again, but using a PageFormat with landscape orientation
In the second case, you'll find that the page won't be rotated correctly.
======================================================================
- duplicates
-
JDK-4201539 Graphics2D clip does not follow page orientation
- Closed
-
JDK-4221166 pageDialog() does not support landscape format
- Closed
- relates to
-
JDK-4179886 Graphics context returned by PrintJob now includes a clipping region
- Resolved