Solved

Printing multipage TIFFs from an applet.

Posted on 2004-04-16
7
630 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

733 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