我試着打印出我的編輯的內容:頁-範圍-問題在打印文檔
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頁(此頁面大小的設置)。 我測試了它:printdialog出現了,我選擇了頁面範圍(我在文本框中輸入了「1-3」),然後點擊print
。在printdocument()
之上我設置了一個斷點並查看了printdialog對象。它說pd.PageRangeSelection = PageRangeSelection.UserPage
和pd.PageRange = {1-3}
。我想這是對的,因爲我只想打印出1-3頁。然後printdocument()
執行並在輸出pdf(用於測試我使用pdf打印機)有14頁(整個文件被打印)。
我的錯誤在哪裏?爲什麼頁面範圍設置不起作用?
感謝您的幫助
這不是原因。我已經說過我已經調試過它並且在執行PrintDocument()方法之前將PageRangeSelection-Property設置爲UserPages – 0xDEADBEEF