Hi Phil,

I have tried with the followings jres: jre 1.5_12, jre1.6_3, jre 1.6_EA_5. The 
printer I am using is Epson LX-300+II. The operating system is windows XP sp2. 
I have also tried in UBUNTU. I have set the paper size in the server properties 
of the printer, but it takes the size that it considers is best for printing 
(A5) instead of the size that I am trying to set.With another program like 
wordpad the printer takes the custom paper size I have se in the server 
properties of the printer.


import java.awt.Font;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintTest implements Printable {

        public PrintTest(){
                super();
        }
        public void print() {
                PrinterJob job = PrinterJob.getPrinterJob();
                PageFormat pageFormat = createFormat();
                try {
                        job.setPrintable(this,pageFormat);
                        if (job.printDialog()) {
                                job.print();
                        }
                } catch (PrinterException e) {
                        e.printStackTrace();
                }
        }

        public int print(Graphics graphics, PageFormat pageFormat, int 
pageIndex)
                        throws PrinterException {
                if (pageIndex == 0) {
                        painter(graphics);
                        return PAGE_EXISTS;
                }
                return NO_SUCH_PAGE;
        }

        void painter(Graphics graphics) {
                graphics.setFont(new Font("Sans Serif", Font.PLAIN, 11));
                char[] data = "Printing an area. This is a test that is driving 
me crazy. It is time to come out...."
                                .toCharArray();
                graphics.drawChars(data, 0, data.length, 25, 70);
        }

        public static void main(String[] args){
                PrintTest printTest=new PrintTest();
                printTest.print();
        }

        private PageFormat createFormat() {
                PageFormat format = new PageFormat();
                format.setPaper(new Custom());
                return format;
        }

    private class Custom extends Paper {

                public Custom() {
                        super();
                        setSize(560,491);
                }
        }
}
[Message sent by forum member 'lucho01' (lucho01)]

http://forums.java.net/jive/thread.jspa?messageID=241301

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to