Solved

Printing multipage TIFFs from an applet.

Posted on 2004-04-16
7
642 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 250 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 1

Accepted Solution

by:
cavalmi earned 250 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

626 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