Search This Blog

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");
}