ImageGear .NET v25.2 - Updated
Printing Images with WPF Scaling
Developer Guide > How to Work with... > Common Operations > Printing > Printing in WPF Environment > Printing Images with WPF Scaling

In WPF scaling mode, ImageGear renders all images in their original size and lets WPF scale them. ImageGear does not need to know the printer resolution, so this mode may be preferable when the printer resolution is unknown, or when printing to an XPS printer driver. Note that since ImageGear renders images in their original size, printing low-resolution images to an XPS printer driver produces smaller output files, and printing large, high-resolution images produces bigger output files compared to output files produced by ImageGear Native scaling mode.

The rest of the printing process is the same as with Native scaling mode. The following example demonstrates this:

C#
Copy Code
void PrintWholeImageCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
     System.Windows.Controls.PrintDialog pDialog = new System.Windows.Controls.PrintDialog();
     if(pDialog.ShowDialog() == true)
     {
          // Set up scale settings.
          ImGearRenderSettings rs = new ImGearRenderSettings();

          // Use WPF scale settings - don't need to set resolution.
          // WPF will scale the image.
          ImGearWpfDisplayScaleSettings settings = new ImGearWpfDisplayScaleSettings();
          rs.ImageScaleSettings = settings;

          Canvas printCanvas = new Canvas();

          // Set up Display settings to print whole image.
          ImGearPresentationPageDisplay pageDisplay =
               new ImGearPresentationPageDisplay(imGearPageView.Display.Page, imGearPageView.Display.ARTPage);
          pageDisplay.Layout.FitMode = ImGearFitModes.FIT_TO_DEVICE;

          // printCanvas.Width, printCanvas.Height must be set before
          // pageDisplay.DrawToCanvas, when printing without a pageView.
          printCanvas.Width = pDialog.PrintableAreaWidth;
          printCanvas.Height = pDialog.PrintableAreaHeight;

          // Draw the image on the printCanvas.
          pageDisplay.DrawToCanvas(printCanvas, rs);

          // Arrange canvas size.
          printCanvas.Measure(new Size(
               pDialog.PrintableAreaWidth, pDialog.PrintableAreaHeight));
          printCanvas.Arrange(new Rect(printCanvas.DesiredSize));
       
          // Print the canvas.
          pDialog.PrintVisual(printCanvas, "Print ImageGear image");
     }
}

When using WPF scaling, the application can simply print the canvas that it uses for image display, using PrintDialog.PrintVisual, or any other way supported in WPF. This will display the image with the same layout and physical size as seen on the screen. The following example demonstrates this:

C#
Copy Code
void PrintVisibleAreaCmdExecuted(object target,ExecutedRoutedEventArgs e)
{
     System.Windows.Controls.PrintDialog pDialog = new System.Windows.Controls.PrintDialog();
     if(pDialog.ShowDialog() == true)
     {
          Canvas displayCanvas = imGearPageView.Canvas;

          // Arrange parent canvas.
          displayCanvas.Measure(new Size(
               pDialog.PrintableAreaWidth, pDialog.PrintableAreaHeight));
          displayCanvas.Arrange(new Rect(displayCanvas.DesiredSize));

          // Print the canvas.
          pDialog.PrintVisual(displayCanvas, "Print ImageGear image");
     }
}
Is this page helpful?
Yes No
Thanks for your feedback.