I am trying to print the contents of my editor:
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); }
The test document I used contains about 14 pages (with these page settings). I tested it: printdialog appears, and I selected pagerange (I typed "1-3" into the text box) and hit print
. above printdocument()
I set a breakpoint and looked at the printdialog object. he says pd.PageRangeSelection = PageRangeSelection.UserPage
and pd.PageRange = {1-3}
. I think this is correct because I only wanted to print page 1-3. then the executed printdocument()
and in the output pdf (for testing I use a pdf printer) has 14 pages (the whole document was printed).
where is my mistake Why does the pagerange setting not work?
thanks for the help
source share