Private Function GetFixedDocument2(ByVal flowDoc As FlowDocument) As FixedDocument ' Create a FixedDocument with the same dimensions as A4 paper Dim fixedDoc As New FixedDocument() fixedDoc.DocumentPaginator.PageSize = New Size(793.7, 1122.5) ' 210mm by 297mm converted to points ' Create a FixedPage for each page of content in the FlowDocument Dim paginator As DocumentPaginator = CType(flowDoc, IDocumentPaginatorSource).DocumentPaginator paginator.ComputePageCount() Dim pageCount As Integer = paginator.PageCount For i As Integer = 0 To pageCount - 1 Dim pageContent As New PageContent() Dim fixedPage As New FixedPage() ' Set the dimensions of the FixedPage to match the FixedDocument fixedPage.Width = fixedDoc.DocumentPaginator.PageSize.Width fixedPage.Height = fixedDoc.DocumentPaginator.PageSize.Height ' Get the content of the current page of the FlowDocument Dim flowContent As DocumentPage = paginator.GetPage(i) ' Create a DrawingVisual to render the content Dim drawingVisual As New DrawingVisual() Using drawingContext As DrawingContext = drawingVisual.RenderOpen() drawingContext.DrawRectangle(New VisualBrush(flowContent.Visual), Nothing, New Rect(New Point(), flowContent.Size)) End Using ' Create an Image and set its source to the DrawingVisual Dim pageImage As New Image() pageImage.Source = New DrawingImage(drawingVisual.Drawing) ' Add the Image to the FixedPage fixedPage.Children.Add(pageImage) ' Add the FixedPage to the PageContent pageContent.Child = fixedPage ' Add the PageContent to the FixedDocument fixedDoc.Pages.Add(pageContent) Next Return fixedDoc End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)