Printing

Note: new printing capabilities are on the way, but will not be shipped with the product until 6.5. You can add these capabilities to existing projects by following the instructions listed here: http://dev.wavemaker.com/forums/?q=node/6944

Printing is hard to do in WaveMaker. Recommendations on doing this well are unfortunately unsatisfactory. The problem boils down to having a framework that manages domNodes very precisely to get an efficient and polished result that works great in the browser… and doesn't work at all for printing. Nonetheless, here are our recommendations.

Experimental new print methods

A print() method has been added to 6.4 for all controls. You can call this.layoutBox1.print() or this.dojoGrid1.print() or print on any panel. This is a very experimental feature but is the easiest way to get basic printing working. Here are some tips on using it:

  • Currently, you don't have any control over background color; we'll change this in the future, but generally speaking, background colors just burn through ink cartridges
  • Currently, the only way to add a border is using a wm.Bevel widget; border styles are ignored
  • You will not be able to create a picture perfect copy of your page design; various approximations are made; these will be refined over time, but this rule will remain important to understand.
  • Typical web pages are 800-1200px wide. For best results, either hide panels such as your table of contents that adds to the width of your page, or only priint a panel that looks good at 750px width.
  • Spacer don't yet work; this will be fixed in 6.5.
  • Setting padding and margin generally won't work for adding spacing; use width to change spacing

Print only a single page

If everything you need to print can be fit onto a single printed page, then printing should work well. If this situation describes you, then issues of printing from the framework don't apply to you, your user can just hit the browser's print button and be done with it. There is always room to improve the result; and there are sections below to help with this, but your task is relatively simple.

Use third party reporting tools

Rather than trying to force your project to generate printable pages, you can use a third party tool such as Jasper Reports to generate printable reports.

Open a new window and pack in some custom Html

You can always implement a print button that does something like this:

printButtonClick: function(inSender) {
    var win = window.open("");
    var doc = win.document;
    doc.open("text/html");
    doc.write("<html><body onload='window.print()'>");
    doc.write(...) // write your html and data
    doc.close();
}

I'll say this straight up: this is a lot of work and will take a lot of polish.

Iterate through all of your widgets changing layout style

One technique which has been used successfully but is also a lot more work than is recommended: Iterate through every container on your page and change the dom node's position from absolute to static; and remove the height so that there are is no need for printing to manage autoScrolling containers.

For example, the following (untested) code might get you closer to a solution:

printButtonClick: function(inSender) {
      wm.forEachWidget(app._page.root, function(w) {
          if (w instanceof wm.Container) {
             w.domNode.style.position = "static";
             w.domNode.style.height = ""; // let the domNode figure out a height for itself
          }
      });
      // Give the browser time to render the new page before we print it
      window.setTimeout(function() {window.print();}, 1);
}

Expect the above code to make a real mess of your page. Use of this technique is best when using very very simple layouts. You may also want to cause widgets to hide if they aren't going to print well. Finally, when all of this is done, your page will still be a mess, and you'll either need to reload the page or undo every dom change you just performed.

An important technique for printing is Print CSS

http://www.alistapart.com/articles/goingtoprint/


      Share/Bookmark
© 2012 VMware, Inc. All Rights Reserved.