Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page-Range-Problem at Printing a Document

i try to print out the content 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 has about 14 pages (with this pagesize-settings). i tested it: the printdialog appears and I´ve chosen a pagerange (i typed "1-3" into the textbox) and clicked print. above the printdocument() I set a breakpoint and looked into the printdialog-object. it says pd.PageRangeSelection = PageRangeSelection.UserPage and pd.PageRange = {1-3}. I guess this is right, because I wanted to print out only page 1-3. then the printdocument() executed 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 your help

like image 412
0xDEADBEEF Avatar asked Sep 18 '11 12:09

0xDEADBEEF


People also ask

How do I set the page range on my printer?

Open the print dialog by pressing Ctrl + P . In the General tab, choose Pages from the Range section. Type the numbers of the pages you want to print in the text box, separated by commas. Use a dash to denote a range of pages.


1 Answers

In your code you manually set:

pd.PageRangeSelection = PageRangeSelection.AllPages;

This is why your code prints all the pages.

like image 177
VMAtm Avatar answered Oct 26 '22 18:10

VMAtm