Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing multipage TIFFs from an applet.

Posted on 2004-04-16
7
Medium Priority
?
650 Views
Last Modified: 2012-06-21
Hi Folks,

I need to be able to print multipage tiffs from an applet (usning IE6.x and JDK1.4). The code below does work however it takes about 2-3 minutes per page. Some of the tiffs I need to print are 20 pages in size. As you can imagine waiting over an hour for a doc to print isn't going down very well. I've attempted turning off double buffering which stop huge spool files being created, however doesn't speed up the print. I've also disabled postscript printing on the printer (read somewhere that this can cause slow printing) but to no avail.

Any ideas? I need to get the printing speed around the same speed as printing directly from windows?

Document print

      if (name.equals("buttonPrint"))
      {
          //Custom button text
          Object[] options = {"Print All Pages", "Print Selected Page", "Cancel Print"};
                             
          int n = JOptionPane.showOptionDialog(
            null, "Would you like to print all the pages or the selected page?",
            "Print",  JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[2]);
               
          if (n == 0)
          {
            try
            {
              // print all pages
              // Open the file.
             
               viewPanel.setDoubleBuffered(false);
             
             
             
              // Don't need to make second call to the URL to get Image
             
              //Page p = PageGetter.getPage(printURL);
              Page p = annotationViewer.getImageSource();
             
             
              p.load(null);

 
              while (p.getState() != Page.PAGE_STATE_LOADED)
              {
                Thread.sleep(500);
              }

     


              AnnotatedPagePrintable app = new AnnotatedPagePrintable(p, true);
         
              // Create a PrinterJob.
              PrinterJob pj = PrinterJob.getPrinterJob();

              // Set the margins.
              PageFormat pf = pj.defaultPage();
           
              // Now Print the page.
              pj.setPrintable(app, pf);
             
              pj.print();
             
              viewPanel.setDoubleBuffered(true);
             
          }
          catch (Exception ex)
          {
             //  Something went wrong.
            ex.printStackTrace();
          }
        }
        else if (n == 1)
        {
          annotationViewer.printImage();
        }    

      }      

0
Comment
Question by:fintan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 750 total points
ID: 10840755
Printing was a late addition (especially to the Java2D api), and priority was placed on the rendering aspect, not the printing aspect...

Assuming you are using the latest 1.4.2 version of java, there is not much else you can do...  All of the time is being used up spooling the image section to a spool file, and then convering the java2d calls to printer commands...

Maybe if you could save the picture into some other file format?  So that a native Windows app could load and print it?

I hope that I'm wrong, but your code looks fine to me (and the same way I would do it)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10840777
This guy is having the same problem...

http://forum.java.sun.com/thread.jsp?thread=368042&forum=54&message=1554932

Hmmmm...
0
 

Author Comment

by:fintan
ID: 10840903

Jezzz.... That's tragic. It's not like the files are big or anything. A single page is less than 60k and the multipage doc is around 500K.

Is converting the image to another format not likely to cause the same problem when I attempt to print?

Using the windows app isn't really a runner. The client went for the browser based app because of the ease of deployment etc. I had thought about a windows based print server on one machine, but the end users are spread out over a few building with about 100 printers...


Cheers,

Fintan
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 1

Accepted Solution

by:
cavalmi earned 750 total points
ID: 10840922
You may want to have a look at the following:
http://www.snowbound.com/products2/tools_java.html

Also, the following suggestion may not help because my solution for a similar problem was in an application, not an applet.

I was attempting to print pdf files and found similar wait times.  I used an external program to convert pdf to postscript and then sent the postscript to the printer.  If you can find a library to convert the tiff to postscript this may be of some use.

0
 

Author Comment

by:fintan
ID: 10841031

Cavalmi,

I tried the snowbound stuff, but those guys sure know how to charge for the toolkit. It was gonna cost some where in the region of £6000 - £8000 depending on the configuration and (I think) there was a per seat licensing charge for end users.

I'll have a hunt for a pdf to postscript lib and see if it does the job
Cheers,
Fintan
0
 

Author Comment

by:fintan
ID: 10866852
I haven't been able to find a tiff2ps library... but as cavalmi and tim have pointed out it appears to be an issue with the JDK... and I'll probably have to live with it...

Cheers,

Fintan
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10867469
Hopefully it will be sorted out in 1.5...  I have heard rumours that it is much faster with java2d...not tested it yet though...

Good luck!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question