Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Collating

Thread view: 
freesoft_2000 - 12 Jul 2006 17:13 GMT
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
danharrisandrews@gmail.com - 12 Jul 2006 20:12 GMT
Hi Richard,

Strange indeed that the cross platform print dialog and the system
specific print dialog produce different results. Results like this have
led people and companies to create their own Java printing
infrastructures. Printing in Java is getting better over the years, but
there is room for improvement in easy of use for the developers and
improvement in the end user experience. If you are interested in a
light weight multi-platform printing infrastructure, then please don't
hesitate to look at our printing demonstration (www.ansir.ca/demos.jsp)
or download our evaluation API (www.ansir.ca/downloads.jsp).

Cheers,

Dan Andrews
- - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - -

> Hi everyone,
>
[quoted text clipped - 109 lines]
>
> Richard West


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.