开发者

Avoid multiple columns in printing FlowDocument

开发者 https://www.devze.com 2023-04-08 05:50 出处:网络
I am writing code to print from a FlowDocument. PrintDialog printDialog = new PrintDialog(); bool开发者_运维技巧? result = printDialog.ShowDialog();

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; 


In case, there is no printDialog involved (e.g. Writing a XML-File), this solution worked for me:

        .PagePadding = New Thickness(50)
        .ColumnGap = 0
        .PageWidth = 21 * 96 / 2.54
        .PageHeight = 29.7 * 96 / 2.54

        .ColumnWidth = .PageWidth - .PagePadding.Left - .PagePadding.Right
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号