【问题标题】:Multiple page printing in Silverlight 4 using Custom Printing Template (a User Control)Silverlight 4 中使用自定义打印模板(用户控件)进行多页打印
【发布时间】:2011-03-14 00:48:43
【问题描述】:

我需要一些关于使用自定义打印模板打印多页的帮助。打印模板(Silverlight 用户控件)由两个文本块(标题和内容显示并稍后打印相应的文本)组成。我遇到的问题是它只能打印 1 页,如何扩展它以打印多页。这是工作流程 -

  • 内容(要打印的可能非常大)首先显示在嵌入在子窗口(一种自定义消息框)中的文本块上。
  • 此内容需要打印,所以我创建了一个自定义打印模板,它将分别打印标题和内容。
  • 现在,我不确定如何扩展它以打印多页。

这是我的 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>

还有我的代码 -

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

需要一些逻辑来检查 TitleTextBlock 的总大小并创建 PrintingTemplate 的新实例。有人可以就我如何实现这一点提出一些指示吗? (我希望我能够为我的问题提供足够的信息)。

【问题讨论】:

    标签: silverlight printing silverlight-4.0


    【解决方案1】:

    我能做到的最好的就是这样做 - 提出一些指示!前几天我发现了这篇文章,发现在 Silverlight 中打印远没有我想象的那么简单,我想它可能会派上用场。

    http://www.gal-systems.com/2/post/2011/02/multiple-pages-printing-in-silverlight-4.html

    第二部分,用于生成打印预览:

    http://www.gal-systems.com/2/post/2011/02/multiple-page-printing-in-silverlight4-part-2-preview-before-printing.html

    让我们知道你的进展情况!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多