Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JAva Printing (Paper Size)

807569Jul 6 2006 — edited Jul 6 2006
Hello

I've got a big problem when printing some labels to a printer from java.
The label printer is a Toshiba Tec B-SV4

I need to print some labels to the printer. The labels have a 4 by 4 inch size.
The first thing I do is select the printer:
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        
        try {
            printerJob.setPrintService(services[selectedService]);
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
Then I pass some attributes:
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
        MediaSizeName mediaSizeName = MediaSize.findMedia(4,4,MediaPrintableArea.INCH);
        System.out.println(mediaSizeName.toString());
        printRequestAttributeSet.add(mediaSizeName);
        printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 288, 288,MediaPrintableArea.INCH));
I also set the page format:
        PageFormat pf = new PageFormat();//pj.defaultPage();
         Paper p = new Paper();
         p.setSize(288,288); // about 4in x 4in
         p.setImageableArea(0,0,288,288);
         pf.setPaper(p);
        printerJob.setPrintable(this,pf);
        printerJob.setPrintable(this,printerJob.pageDialog(pf));
The problem comes when printing.
If I show the native print dialog to the user (WindowS), the correct paper size for the label is not selected.
Instead, if I show the cross-platform printDialog, the correct paper size doesn't appear in the options, the options shoud be "User, 2 x 4, 4 x 4, 4 x 6", instead, you just can select between "2 x 4 and 4 x 6".
In the native version, all options appear

Any suggestions?

ThanlYou
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2006
Added on Jul 6 2006
3 comments
653 views