WPF将字符串打印为行

时间:2014-05-02 18:42:08

标签: c# wpf printing

在我的应用程序中,我必须将一些数据打印到打印机。此数据存储在一个集合中,集合中的每个记录都有一个字符串字段,即要打印的内容。这些字符串字段中的每一个都应该是一行。我想要做这样的事情

FlowDocument doc = new FlowDocument();
foreach (var x in myCollection)
{
    Paragraph p = new Paragraph(new Run(x.PrintString));
    doc.Blocks.Add(p);
}
doc.Name = "FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDlg.PrintDocument(idpSource.DocumentPaginator, "My Printing");

问题是每一行后面都有一个空格,就像这样;

Line 1

Line 2

Line 3

当我需要它时看起来像这样;

Line 1
Line 2
Line 3

由于

编辑:添加doc的定义 根据评论,我能够使用以下

FlowDocument doc = new FlowDocument();
Paragraph p = new Paragraph();
foreach (var x in myCollection)
{
    p.Inlines.Add(x.PrintString + "\r\n");
    p.Margin = new Thickness(0);
}
doc.Blocks.Add(p);
doc.Name = "FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDlg.PrintDocument(idpSource.DocumentPaginator, "My Printing");

0 个答案:

没有答案