Solved

Printing multipage TIFFs from an applet.

Posted on 2004-04-16
7
625 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now