c# - 打印文档时的页面范围问题

标签 c# printing printdialog

我尝试打印出我的编辑器的内容:

PrintDialog pd = new PrintDialog();

pd.PageRangeSelection = PageRangeSelection.AllPages;
pd.UserPageRangeEnabled = true;

FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(CurrentDocument.Editor);
DocumentPaginator dp = ((IDocumentPaginatorSource)fd).DocumentPaginator;

bool? res = pd.ShowDialog();

if (res.HasValue && res.Value)
{
    fd.PageHeight = pd.PrintableAreaHeight;
    fd.PageWidth = pd.PrintableAreaWidth;
    fd.PagePadding = new Thickness(50);
    fd.ColumnGap = 0;
    fd.ColumnWidth = pd.PrintableAreaWidth;

    pd.PrintDocument(dp, CurrentDocument.Editor.FileName);
}

我使用的测试文档大约有 14 页(使用此页面大小设置)。 我对其进行了测试:打印对话框出现,我选择了一个页面范围(我在文本框中键入了“1-3”)并单击了print。在 printdocument() 上方,我设置了一个断点并查看了 printdialog 对象。它说 pd.PageRangeSelection = PageRangeSelection.UserPagepd.PageRange = {1-3}。我想这是对的,因为我只想打印第 1-3 页。然后执行 printdocument() 并在输出 pdf 中(为了测试我使用 pdf 打印机)有 14 页(打印了整个文档)。

我哪里错了?为什么 pagerange-setting 不起作用?

谢谢你的帮助

最佳答案

在您手动设置的代码中:

pd.PageRangeSelection = PageRangeSelection.AllPages;

这就是您的代码打印所有页面的原因。

关于c# - 打印文档时的页面范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7461518/

相关文章:

php - 在 PHP 中打印到打印机

c++ - 在 Debian、C++ 中,自动查找打印机的节点

c# - 打印前显示打印对话框

c# - 使用 RegEx 提取许多电话号码

c# - Unity中的简单键盘输入

java - 将矩形打印到 JPanel 上的图像上

WPF Documentviewerbase.Print。删除对话框

c# - 从 C# 中的构造函数调用实例方法

c# - 如何将完整的 Sqlite 连接字符串传递给 DbContext