yFiles WPF offers various possibilities for printing the contents of a CanvasControl. Readily available with class CanvasControl, for example, are the following methods:
bool Print() |
|
| Description | CanvasControl's printing methods. They enable enable both instant printing mostly using the canvas's current settings or presenting a user the full-blown printing user interface. |
Ultimately, both these methods use class
CanvasPrintDocument
for the actual
printing.
CanvasPrintDocument provides all necessary functionality for printing the
contents of a canvas.
It supports scaling and clipping options, and also enables poster printing.
Figure 2.40, “CanvasPrintDocument” gives an overview on the hierarchy of printing
classes.
The CanvasControl whose content is to be printed is given either at creation
time of the instance or using the
Canvas
property.
Specifying the part of the canvas that should be printed is done in world
coordinates using the
PrintRectangle
property.
Unless a clipping is explicitly provided that way, the entire contents of the
canvas, i.e., the rectangle as returned by the CanvasControl's
ContentRect property, is printed.
Example 2.47, “Printing a canvas's currently visible contents” shows how to print the currently visible contents
of a control.
Example 2.47. Printing a canvas's currently visible contents
public void PrintVisible(CanvasControl control) {
// Print the currently visible contents of the given control.
CanvasPrintDocument cpd = new CanvasPrintDocument(control);
cpd.PrintRectangle = control.Viewport;
cpd.Print(false, false);
}
CanvasPrintDocument allows to apply a scaling factor when printing the
rectangle that is specified with the PrintRectangle property.
This factor can be conveniently set by means of the
Scale
property.
Initially, however, CanvasPrintDocument prints only one page regardless of the
actual dimensions of the scaled print rectangle.
Due to the
ScaleDownToFitPage
property, which is true by default, poster printing is effectively
disabled.
Example 2.48, “Enabling poster printing” shows how to switch CanvasPrintDocument from single-page mode to poster printing and how to specify a scaling factor to be applied when the visible contents of a control are printed.
Example 2.48. Enabling poster printing
// 'control' is of type yWorks.Canvas.CanvasControl. CanvasPrintDocument cpd = new CanvasPrintDocument(control); // Effectively disables single-page mode. cpd.ScaleDownToFitPage = false; cpd.PrintRectangle = control.Viewport; cpd.Scale = 2.0; cpd.Print(false, false);
The number of columns and rows for poster printing is automatically derived from the actual dimensions of the scaled print rectangle during the printing process. The following method can be used to query the values for column and row count:
Size CalculatePosterSize(PageMediaSize size, InsetsD margins) |
|
| Description | Calculates the number of columns and rows for the scaled print rectangle. |
|
Copyright ©2008-2011, yWorks GmbH. All rights reserved. |