Hi,
I have a problem in printing. setOreintation() on PageFormat appreantly
does not have any effect. Our application does NOT require a pagedialog
or printdialog. The prinout has to be in REVERSE_LANDSCAPE mode only. I
explicitly call
PrinterJob prnJob = PrinterJob.getPrinterJob() ;
PageFormat pf = prnJob.defaultPage() ;
pf.setOrientation( PageFormat.REVERSE_LANDSCAPE) ;
The resultant output is like PORTRAIT orientation. I am giving below a
sample code.
Could someone please throw light on this problem.
Thanks.
ganesan
------------------------- sample code ----------------
import javax.swing.* ;
import java.awt.* ;
import java.awt.print.* ;
public class HorizontalLine implements Printable
{
public HorizontalLine()
{
super() ;
}
public void paint( Graphics g )
{
g.setColor(Color.black);
g.drawLine( 100 , 100 , 300 , 100 ) ;
}
public int print(Graphics g, PageFormat pf, int pi) throws
PrinterException
{
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
paint(g);
return Printable.PAGE_EXISTS;
}
public static void main( String[] args )
{
// Get a PrinterJob
PrinterJob prnJob = PrinterJob.getPrinterJob();
PageFormat pf = prnJob.defaultPage();
// orientation has no effect
pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
prnJob.setPrintable(new HorizontalLine() , pf );
try
{
prnJob.print();
}
catch (PrinterIOException e)
{ /* handle exception */
System.out.println( e ) ;
}
catch (Exception e)
{ /* handle exception */
System.out.println( e ) ;
}
}
}
HorizontalLine.java