我尝试打印出我的编辑器的内容:
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.UserPage
和 pd.PageRange = {1-3}
。我想这是对的,因为我只想打印第 1-3 页。然后执行 printdocument()
并在输出 pdf 中(为了测试我使用 pdf 打印机)有 14 页(打印了整个文档)。
我哪里错了?为什么 pagerange-setting 不起作用?
谢谢你的帮助
最佳答案
在您手动设置的代码中:
pd.PageRangeSelection = PageRangeSelection.AllPages;
这就是您的代码打印所有页面的原因。
关于c# - 打印文档时的页面范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7461518/