freesoft_2000 9 Practically a Master Poster

Hi everyone,

I have a question about the java multi-platform print dialog.

My question is on collating the output of my print out using the java multi-platform print dialog. The thing is no matter even if i select the collate check box or not the output of the print out is always printed uncollated.

When i use the platform specific print dialog(windows in my case) the output can be printed collated or uncollated.

This is what i am doing to call the multi-platform dialog to print collated print-outs

The below is sun's simple printing program but when i test this programming(when i switch the aset variable between collating and uncollating) the problem also arises.

This is the compilable program

import java.awt.*; 
import java.awt.print.*;
import javax.print.attribute.standard.*;

	public class PrintBook {
  	  public static void main(String[] args) { 

      javax.print.attribute.PrintRequestAttributeSet aset;
      aset = new javax.print.attribute.HashPrintRequestAttributeSet();

  	  aset.add(new Copies(2));
      //aset.add(SheetCollate.UNCOLLATED);
      aset.add(SheetCollate.COLLATED);
    
    		// Get a PrinterJob     
    		PrinterJob job = PrinterJob.getPrinterJob();     
    		// Create a landscape page format    
    		PageFormat pfl = job.defaultPage();  
    		pfl.setOrientation(PageFormat.LANDSCAPE);     
    		// Set up a book     
    		Book bk = new Book();     
    		bk.append(new PaintCover(), pfl);     
    		bk.append(new PaintContent(), job.defaultPage());     
    		// Pass the book to the PrinterJob     
    		job.setPageable(bk);     
    		// Put up the dialog box     
    		if (job.printDialog(aset)) { 
      		   // Print the job if the user didn't cancel printing
      		   try { job.print(aset); } 
      		   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;   
  	   } 
	}
	class PaintContent implements Printable {   
  	   public int print(Graphics g, PageFormat pf, int pageIndex)
  		throws PrinterException {    
    		Graphics2D g2 = (Graphics2D) g;     
    		int useRed = 0;     
   		int xo = (int) pf.getImageableX();
		int yo = (int) pf.getImageableY(); 
    		// Fill page with circles or squares, alternating red & green
		for (int x = 0; x+28 < pf.getImageableWidth(); x += 36)
    		for (int y = 0; y+28 < pf.getImageableHeight(); y += 36){ 
      		   if (useRed == 0) g.setColor(Color.red);
      		   else g.setColor(Color.green);
      		   useRed = 1 - useRed;
      		   if (pageIndex % 2 == 0) g.drawRect(xo+x+4, yo+y+4, 28, 28);
      		   else g.drawOval(xo+x+4, yo+y+4, 28, 28);
    		}     
    		return   Printable.PAGE_EXISTS;   
  	   } 
	}

It seems strange to me that if i use the sytem specific print dialog i can print both collated and uncollated printouts but if i use the java multi-platform print dialog the print out is always printed uncollated even when i specify it to be printed collated

There are no exceptions thrown and the program compiles with no errors.

Am i calling java multi-platform print dialog and adding the
attributes correctly?

Is this a bug or am i missing something for both my questions?

This program was run on java 1.4.6 and 1.5.0_06 with both producing the same results

I really hope someone can help me with this problem

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.