Multiple page printing in Silverlight 4 using Custom Printing Template (a User Control)
I need some help on printing multiple pages with custom printing template. The printing template (a Silverlight User Control) consists of two Text-block's (Title and Content which displays and later prints the respective text). The problem I am having is its only able to print 1 page, how can I extend it to print multiple pages. This is the work flow -
- The content (to be printed which can be very large) is first displayed on text block embedded in Child Window (kind of customized message box).
- This content needs to be printed, so I created a custom printing template which will print title and the content separately.
- Now, I am not sure how can I extend it to print multiple pages.
Here's my xaml -
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,10,10" >
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="10" BorderThickness="5" Background="White" Height="50" >
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="2" TextWrapping="Wrap" Name="TitleTextBlock" FontSize="16"
TextAlignment="Center" FontFamily="Times New Roman" FontStyle="Italic" FontWeight="SemiBold" >
</TextBlock>
</Border>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="10" Margin="0,10,0,0" BorderThickness="5" Background="White" Height="950" >
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" TextWrapping="Wrap" Name="ContentTextBlock" FontSize="14"
FontFamily="Times New Roman" FontWeight="Normal" >
</TextBlock>
</Border>
</StackPanel>
and my code -
开发者_如何学PythonPrivate Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
printDoc.Print("MyTest")
End Sub
Private Sub printDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim printPage As New PrintingPageTemplate
'printPage.PageTitle = Me.Title.ToString
'printPage.PageContent = Me.txtMessage.Text
printPage.TitleTextBlock.Text = Me.Title.ToString
printPage.ContentTextBlock.Text = Me.txtMessage.Text 'The txtMessage is a text block which consists of data to be printed and it can have very large content
e.PageVisual = printPage
'e.HasMorePages = True ' This doesn't work
End Sub
Need some logic which will check the total size of TitleTextBlock and create new instance of PrintingTemplate. Can someone please throw some pointers on how can I achieve this? (I hope I was able to provide enough information for my problem).
The best I can manage is to do just that - throw some pointers! I found this article the other day and thought it would probably come in handy after discovering that printing in Silverlight is far from as simple as I'd figured it would be.
http://www.gal-systems.com/2/post/2011/02/multiple-pages-printing-in-silverlight-4.html
and the second part, for generating a print preview:
http://www.gal-systems.com/2/post/2011/02/multiple-page-printing-in-silverlight4-part-2-preview-before-printing.html
Let us know how you get on!
精彩评论