views:

62

answers:

0

Hello everyone,

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 -

Private 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).