[WPF 学习] 7.1 多页打印
Posted catzhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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 多页打印的主要内容,如果未能解决你的问题,请参考以下文章
后端返回PDF文件流,前端处理展示及打印(补:PDF多页不显示问题)