在不同页面上打印FlowDocument块

时间:2009-09-11 07:13:58

标签: wpf printing flowdocument

我使用以下代码打印FlowDocument

        PrintDialog dialog = new PrintDialog();
        var value = dialog.ShowDialog();

        if (value.HasValue && value.Value == true)
        {
            XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue);
            PageImageableArea imageArea = dialog.PrintQueue.GetPrintCapabilities().PageImageableArea;
            PrintTicket ticket = dialog.PrintTicket;

            if (writer != null && imageArea != null)
            {
                DocumentPaginator paginator = (doc as IDocumentPaginatorSource).DocumentPaginator;
                paginator.PageSize = new Size((double)ticket.PageMediaSize.Width, (double)ticket.PageMediaSize.Height);
                var padding = doc.PagePadding;
                doc.PagePadding = new Thickness(
                      Math.Max(imageArea.OriginWidth, padding.Left),
                      Math.Max(imageArea.OriginHeight, padding.Top),
                      Math.Max((double)ticket.PageMediaSize.Width - (double)(imageArea.OriginWidth + imageArea.ExtentWidth), padding.Right),
                      Math.Max((double)ticket.PageMediaSize.Height - (double)(imageArea.OriginHeight + imageArea.ExtentHeight), padding.Bottom));
                doc.ColumnWidth = double.PositiveInfinity;
                // Send DocumentPaginator to the printer.
                writer.Write(paginator);
            }
        }

现在我想在不同的页面上打印一个单独的doc块,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用元素或元素MSDN

根据您实际想要做的事情,您必须在文档中添加块:

doc.AddBlocks(newblock)