[WPF 学习] 7.1 多页打印

2021-03-14 03:43

阅读:663

标签:ali   int   open   flow   context   nta   doc   size   rect   

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 多页打印

标签:ali   int   open   flow   context   nta   doc   size   rect   

原文地址:https://www.cnblogs.com/catzhou/p/12502880.html


评论


亲,登录后才可以留言!