zoukankan      html  css  js  c++  java
  • [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");
    
  • 相关阅读:
    616无趣
    安装elasticsearch的问题
    导出PDF数据
    生活本苦,奈何年华
    分享一个sql查询重复记录
    springboot的java打印票据-4
    springboot的java打印票据-3
    springboot的java打印票据-2
    react 学习笔记
    原生可拖动表格
  • 原文地址:https://www.cnblogs.com/catzhou/p/12502880.html
Copyright © 2011-2022 走看看