Personal tools

Printing

From OpenLaszlo

Contents

Proposed Printing API for LPS3

Typically you don't want to print exactly what is displayed on the screen, but rather create a different layout formatted for printing.

I propose to create a subclass of view, called "printview" and it acts just like any other view, except it has an additional "print" method. When you call print, it would pop up a standard printer dialog and after the user clicks "OK," everything within the bounding box of the view would be printed.


For example:

 <printview id="printer">
       ...
 </printview>
 <button onclick="printer.print()"/>

Use Cases

Screen=printer; whole canvas

In this use case, an application has the same layout on the screen and print medium, and that layout is the entire canvas.

This would be accomplished by wrapping everything in the printer view. The original application:

 <canvas>
   ...
 </canvas>

would be changed to:

 <canvas>
   <printview id="printer">
     ...
   </printview>
   <button onclick="printer.print()"/>
 </canvas>

Screen=print; canvas portion

Only a portion of the canvas is printed, but this portion is printed with the same layout as on screen.

<canvas>
   some views
   <printview id="printer>
     ...
   </printview>
 </canvas>

Printing-specific layout, without preview (not available?)

This is an application that has one layout for the screen, and another for print media; and where the print layout is not displayed prior to printing.

The <printview> could be positioned off-screen so as not to appear to the end-user.

Printing-specific layout, with preview

This is the same as the screen=print cases. Screen-only views are outside the <printview>; print-only views are inside the printview.

Multi-Page Printing (not available)

Not available under this API.

Documentation Examples (not available)

It would be nice to use this API to capture screen shots for documentation examples. This could only be done if there were a programmatic API for invoking the print function, that did not depend upon editing the program source.

Questions

Q: Is it possible to implement a "Fast Print" (the old "Print One" menu item on the Macintosh, that bypasses the print dialog? A: I have not seen a Flash API to support this.

Comparisons

Flash API

The Flash script:

print("printer", "bframe")

compiles into:

 getURL("print:#bframe", "printer")

The first param is the movie clip target, the second is a bounding box flag (Flash docs for print) . I plan to use the "bmovie" flag and create a second frame (with label #b) that can be sized to the width and height of the the view.

There's a PrintJob class that only works in Flash 7.

CSS

All views are displayed to the screen and to print layout by default. Views can be removed from the print layout by adding a CSS line that selects and disables them:

 @media print {.screen {display: none}}

Views can also be removed from the print layout:

 @media print {.screen {display: none}}

This allows a page to be partioned into areas specific to screen media, to print media, and shared among them:

...
...
both
...

The advantages of the CSS solution are that it supports multiple media types (for example, voice), and that it allows fine-grained definition of screen- and print-specific layouts as deltas from a baseline layout. The proposed LZX API requires duplication of source fragments to make minor modifications (or else parameterizable class definitions).

The disadvantage of the CSS solution are that as it stands it supports only a single print layout for each document. The LZX solution allows multiple printed "reports", through the use of multiple <printview> elements.

Further Discussion

jgrandy:

It turns out there are some PrintJob properties that are not described on that one page. They are orientation, pageHeight, pageWidth, paperHeight, paperWidth.

I found this in Flash8 documentation:

http://livedocs.macromedia.com/flash/8/main/00002608.html

but it is also documented for Flash 7:

http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001642.html

Here is the revised proposal, as written by Henry Minsky. It doesn't include the PrintJob properties mentioned above.

OpenLaszlo Printing API

Flash 7 has a multipage PrintJob API which we can use. It is based on printing movieclips. We can have a basic wrapper which maps to that model to provide printing of LzView objects.

A simple example of the API used to print three pages, one view per page, would be:

var job = new LzPrintJob();

if (job.start()) {

   var ok = job.addPage(view1);
   ok |= job.addPage(view2);
   ok |= job.addPage(view3);

   if (ok) {
      job.send();
   }
}

Printing API



Constructor: new LzPrintJob()
Create new LzPrintJob object

<p> Returns: LzPrintJob object <p>


<dt>Method: LzPrintJob.start() <dd> <p> Pops up dialog box for use to choose printer, options.

<p> Returns: true if user selects printing, false if user cancels or error occurs <p>

<dt>Method: LzPrintJob.addPage(view, printArea, options) <dd> <p> view: An LzView object to print <p>

printArea: A hash table containing a bounding box, in pixels, of the form {xMin:topLeft, xMax:topRight, yMin:bottomLeft, yMax:bottomRight} <p>

options:

A hash table containing these options
  • printAsBitmap: boolean, defaults to false <li>scaleX: float to scale x dimension <li>scaleY: float to scale y dimension </ul> When false, the printAsBitmap flag causes vector and text to be rendered at printer resolution. When set to true, the media are rendered at screen resolution. If there are bitmaps which contain transparency values, printAsBitmap must be set to true to render properly. <p> Returns: true if page successfully sent to the print spooler, false otherwise <p> <dt>Method: LzPrintJob.send() <dd> <p> Send spooled pages of the current LzPrintJob to the printer. <p> Returns: nothing </dl>