1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Imports System
Imports System.Printing
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Documents.Serialization
Imports System.Windows.Markup
Imports System.Windows.Media
Imports System.Windows.Shapes
Imports System.Windows.Xps
Namespace PrintCanvasFixedDoc
Partial Public Class Window1
Private m_printQueue As PrintQueue
Private m_printTicket As PrintTicket
'garder une reference à XPS document en cours.
Private m_xpsDocumentWriter As XpsDocumentWriter
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.dvDocumentViewer.Document = CreateMultiPageFixedDocument()
End Sub
'Cree un FixedDocument avec nombreuse pages.
Public Function CreateMultiPageFixedDocument() As FixedDocument
Dim m_fixedDocument As FixedDocument = New FixedDocument()
m_fixedDocument.DocumentPaginator.PageSize = New Size(96 * 8.5, 96 * 11)
'cree 10 pages
For i As Integer = 0 To 10
Dim m_pageContent As PageContent = New PageContent()
m_fixedDocument.Pages.Add(m_pageContent)
Dim m_fixedPage As FixedPage = New FixedPage()
'Ajoute le canvas personnalise CanvasSrollableZoom avec un
'TextBlock et un Rectangle comme enfants.
Dim m_canvas As CanvasSrollableZoom = New CanvasSrollableZoom
m_canvas.Background = Brushes.Crimson
m_canvas.Visibility = Windows.Visibility.Visible
m_canvas.VerticalAlignment = Windows.VerticalAlignment.Stretch
m_canvas.HorizontalAlignment = Windows.VerticalAlignment.Stretch
m_canvas.Width = 96 * 8.0
m_canvas.Height = 96 * 10
m_fixedPage.Children.Add(m_canvas)
Dim m_textBlock As TextBlock = New TextBlock()
m_textBlock.Text = String.Format("Page {0} / {1}\n\nThis Is Page {0}.", i + 1, 1000)
m_textBlock.FontSize = 24
m_canvas.Children.Add(m_textBlock)
Dim m_rect As Rectangle = New Rectangle()
m_rect.Width = 200
m_rect.Height = 200
m_rect.Fill = New SolidColorBrush(Color.FromArgb(200, 20, 50, 200))
m_canvas.Children.Add(m_rect)
CType(m_pageContent, IAddChild).AddChild(m_fixedPage)
Next
Return m_fixedDocument
End Function
'Presente à l'Utilisateur un PrintDialog pour obtenir une reference
'à PrintQueue.
Public Function GetPrintQueue() As PrintQueue
Dim m_printDialog As PrintDialog = New PrintDialog()
If (m_printDialog.ShowDialog.HasValue And m_printDialog.ShowDialog.Value) Then
Return m_printDialog.PrintQueue
End If
Return Nothing
End Function
Private Sub DocumentViewer_PrintDocument(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
m_printQueue = GetPrintQueue()
m_xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(m_printQueue)
m_xpsDocumentWriter.Write(CreateMultiPageFixedDocument(), m_printTicket)
MessageBox.Show("impression Document terminee...", "CanvasScrollable", MessageBoxButton.OK, _
MessageBoxImage.Information)
Me.Show()
End Sub
End Class
End Namespace |
Partager