我正在编写代码以从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");
}
此代码将在一个页面中打印多个列。怎么避免这个?
答案 0 :(得分:12)
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = printDialog.PrintableAreaWidth;
答案 1 :(得分:0)
如果不涉及printDialog(例如,编写XML文件),则此解决方案对我有用:
.PagePadding = New Thickness(50)
.ColumnGap = 0
.PageWidth = 21 * 96 / 2.54
.PageHeight = 29.7 * 96 / 2.54
.ColumnWidth = .PageWidth - .PagePadding.Left - .PagePadding.Right