0

我的项目需要使用 WPF System.Windows.Controls.PrintDialog 之类的东西将一个简单的字符串对象打印到选择的打印机。

我创建了一个标准 System.Drawing.Printing.PrintDocument,但它没有属于 PrintDialog 类的 PrintDocument() 方法所需的 DocumentPaginator。

将字符串打印到带有对话框以显示打印机选择的打印机似乎是一项微不足道的任务,但结果却要困难得多。请帮忙!

4

1 回答 1

0

由于您使用的是 WPF,而不是使用 PrintDocument,因此只需创建一个FlowDocument。我认为这要容易得多。

var dlg = new PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = false;
if(dlg.ShowDialog() == true)
{                
    var doc = new FlowDocument();
    // For normal A4&/letter pages, the defaults will print in two columns
    doc.ColumnWidth = dlg.PrintableAreaWidth;
    doc.Blocks.Add(new Paragraph(new Run("My arbitrary long string to print.\nNewlines work. Pages will break as needed.")));
    dlg.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Simple document");
}
于 2018-08-16T19:17:36.827 回答