Why is this flowdocument table always printing 2 columns Why is this flowdocument table always printing 2 columns wpf wpf

Why is this flowdocument table always printing 2 columns


I guess the best way to get an answer is to give up and ask, then you find it yourself.

The issue was in the line to print the pages, not the flowdoc itself. By default they print with 2 columns. The corrected code is (this also deals with the margin and printable area):

PrintDialog printDialog = new PrintDialog();if (printDialog.ShowDialog() == true){    FlowDocument flowDoc = statusBoardViewModel.GetPrintDocument();    flowDoc.PageHeight = printDialog.PrintableAreaHeight;    flowDoc.PageWidth = printDialog.PrintableAreaWidth;    flowDoc.PagePadding = new Thickness(25);    flowDoc.ColumnGap = 0;    flowDoc.ColumnWidth = (flowDoc.PageWidth -                            flowDoc.ColumnGap -                            flowDoc.PagePadding.Left -                             flowDoc.PagePadding.Right);    printDialog.PrintDocument(((IDocumentPaginatorSource)flowDoc)                             .DocumentPaginator,                             "Task Manager Print Job");}

By the way I found this in Matthew MacDonald's "Pro WPF in C# 2008" which I highly recommend.


Thanks for the info. I fixed it by just setting the columnwidth like:

flowDoc.ColumnWidth = pageSize.Width

FYI don't ever try to get help from netframeworkdev or .Net Framework Develop b/c they never have good answers. I wish my search engine would have pointed me at StackOverflow instead of that worthless site. StackOverflow always has the answers. :) Thanks again.

(Wish you could just block sites from ever showing in your search results, you know how to do that please tell me.)


Microsoft doc is false/incomplete.

tl;dr: default ColumnWidth resolves to: 320px (for FontSize 16px)

Explanation:

I experienced the default "two column behaviour" too.My flowdocument:

  • PageWidth="8.5in"
  • ColumnWidth="NaN" (default)

8.5in PageWidth translates to (device inpedendent pixels) PageWidth=816px.

From MS docs:"ColumnWidth=Auto" Causes column width to be automatically calculated to be 20 times the current FontSize.

Default font size is 16, so: 20 * 16px == 320px.

So the dirty truth is.NaN (default) behaves as "Auto", which translates to ColumnWidth="320px" for FontSize=16. Which will result in two columns for pages wider than around 640px

  • letter width: 8.5in == 816px
  • A4 width: 210mm == 794px

And of course even more columns if you exceed 960px PageWidth.

How does MS convert physical length to pixels?

new System.Windows.LengthConverter().ConvertFromInvariantString("8.5in");> 816d