Search This Blog

Showing posts with label Printing. Show all posts
Showing posts with label Printing. Show all posts

Monday, October 28, 2013

Printing in WPF

WPF > Printing

Windows Presentation Foundation (WPF) have a rich set of printing and print system management APIs. 
The core of this new functionality is the new XML Paper Specification (XPS) file format and the XPS print path.

Example: Printing a Visual
XAML:
<Window x:Class="Printing.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="Grid">
        <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="91,63,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="75,197,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
     </Grid>
</Window>
Code:
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)

{
    printDialog.PrintVisual(Grid, "My First Print Example");
}

PrintVisual Method WPF

WPF > Printing > PrintVisual

PrintVisual method prints a visual  object to the PrintQueue.

Parameters
  • visual: object to be print
  • description: description of the job that is to be printed

Examples:

Print DataGrid WPF

WPF > Printing > DataGrid

Print DataGrid WPF Example

PrintDialog printDlg = new PrintDialog();
printDlg.PrintVisual(dgProducts, "Grid Printing.");