Raiss
Raiss

Reputation: 321

Client side report generating and printing in Silverlight

I have been working on a project that needs to produce a simple report containing a header, a table with simple grouping and a footer. this report needs a print functionality and it can be more than one page. I found it really difficult to create this report using DataGrid since I can't generate and print more than one page PrintDocument . So far I tried to use iframe (using HTMLPlaceHolder by Telerik) with html report which I generate using silverlight code behind but javascript printing function prints the entire silverlight page. I have telerik and I use it for advance reports but I don't want to use telerik report for this specific report since the report is generating on the server(I don't want to pass any value back to server at all for this report).

Is there any way to generate such a report in client side with printing functionality.

I am open to all suggestion as long as it's not too expensive (up to $100)

Let me know if you need more detail.

Upvotes: 1

Views: 918

Answers (1)

dipak
dipak

Reputation: 2033

You might want to use PrintDocument class in Silverlight. The usage is like..

in XAML file create List as

<ScrollViewer Height="300" VerticalScrollBarVisibility="Auto">
        <ItemsControl x:Name="printSurface">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal"
                Height="25">
                        <TextBlock Width="100"
                 Text="{Binding Name}" />
                        <TextBlock Width="75"
                 Text="{Binding Genre.Name}" />
                        <TextBlock Width="50"
                 Text="{Binding Price, StringFormat=c}" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

and Code behind looks like

   void printButton_Click(object sender, RoutedEventArgs e)
    {
          PrintDocument doc = new PrintDocument();
          doc.PrintPage += new EventHandler<PrintPageEventArgs>(doc_PrintPage);
          doc.Print("Page title");
     }

     void doc_PrintPage(object sender, PrintPageEventArgs e)
      {
       // Stretch to the size of the printed page
       printSurface.Width = e.PrintableArea.Width;
       printSurface.Height = e.PrintableArea.Height;

       // Assign the XAML element to be printed
       e.PageVisual = printSurface;

       // Specify whether to call again for another page
       e.HasMorePages = false;
    }

Upvotes: 1

Related Questions