【问题标题】:Printing and Blazor打印和 Blazor
【发布时间】:2020-06-13 02:51:02
【问题描述】:

我有一个连接到现有后端的Blazor 应用程序。 Blazor 应用需要打印来自 List<T> 的数据。这样做的正确方法是什么?

在 WPF 世界中,我会使用 DocumentPaginator,但是,因为 DocumentPaginator GetPage 方法返回一个 DocumentPage,它是一个 WPF Visual 元素,这已经过时了。

我很幸运地创建了一个 FlowDocument 这样的东西:

var doc = new FlowDocument();
var table1 = new Table();
doc.Blocks.Add(table1);
for (int x = 0; x < numberOfFields; x++)
{
    table1.Columns.Add(new TableColumn());
}
table1.RowGroups.Add(new TableRowGroup());
int i = 0;
foreach (var x in MyList)
{
    table1.RowGroups[0].Rows.Add(new TableRow());   
    TableRow currentRow = table1.RowGroups[0].Rows[i];
    AddFields(currentRow, i, x);
    i++;
}

然而,打印出一个文档,我需要页眉和页脚。使用ParagraphSection 可以很简单地放置页眉、页脚和分页符。问题是计算何时应用分页符。我在 FlowDocument 中看到的所有东西的高度都使用FrameworkElement 来查找它。

对网络非常陌生,所以如果有一些简单的解决方案,我很抱歉。

【问题讨论】:

  • 您确定这是 Blazor 问题吗?
  • 也许可以创建一个 pdf。我对此做了一个小教程:github.com/tossnet/Blazor-PDF
  • 使用 FlowDocument 模型只会做额外的工作。您可以使用 HTML 和 blazor(一个更丰富的工具包)组成一个页面。最后,无论如何您都必须使用 CSS 完成分页。请参阅 thisthis 以及 goole 了解更多信息。

标签: c# blazor flowdocument


【解决方案1】:

结合 TossNet 生成 .pdf 文件,您可以使用Append.Blazor.Printing 显示打印对话框。

可以在此处找到存储库:https://github.com/Append-IT/Blazor.Printing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多