[WPF 学习] 7.1 多页打印

1.自定义打印类

  public class MyDocumentPaginator : DocumentPaginator
        {
            private int _PageCount;
            public override bool IsPageCountValid => true;

            public override int PageCount => _PageCount;

            public override Size PageSize { get; set; }

            public override IDocumentPaginatorSource Source => null;

            public override DocumentPage GetPage(int pageNumber)
            {
                DrawingVisual visual = new DrawingVisual();
                using (DrawingContext dc = visual.RenderOpen())
                {
                    dc.DrawText(new FormattedText($"第{pageNumber}页", System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("仿宋体"), 14, Brushes.Black, 1), new Point(96, 96));
                }
                return new DocumentPage(visual,PageSize, new Rect(PageSize),new Rect(PageSize));
            }

            public MyDocumentPaginator(Size pageSize, int pageCount)
            {
                this.PageSize = pageSize;
                _PageCount = pageCount;
            }
        }

2.调用

            PrintDialog pd = new PrintDialog();
            MyDocumentPaginator doc = new MyDocumentPaginator(new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight), 3);
            pd.PrintDocument(doc, "MyDoc");

[WPF 学习] 7.1 多页打印

上一篇:纵行科技携手意法半导体推ZETA/LoRa双模智能路由,加速LPWAN 2.0泛在物联布局!


下一篇:windows+anaconda下载安装libelimg,学习图像处理