I am writing code to print from a FlowDocument.
PrintDialog printDialog = new PrintDialog();
bool? result = printDialog.ShowDialog();
if (result == true)
{
FlowDocument fd = new FlowDocument();
fd.Blocks.Add(new Paragraph(new Run(String.Format("Message:\r\n{0}\r\n", txtMessage.Text))));
fd.PageHeight = printDialog.PrintableAreaHeight;
fd.PageWidth = printDialog.PrintableAreaWidth;
printDialog.PrintDocument((fd as IDocumentPaginatorSource).DocumentPaginator, "print test");
}
This code will print multiple columns in one page. How to avoid this?
I figured out. I need to set the ColumnWidth of FlowDocument.
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With