Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF FlowDocument printing only to small area

I am printing plain text in WPF by using a FlowDocument, FlowDocumentPaginator and PrintDialog. My approach is based on this article and is implemented as follows:

        var printDialog = new PrintDialog();
        if (printDialog.ShowDialog() == true)
        {
            var flowDocument = new FlowDocument();

            var paragraph = new Paragraph();
            paragraph.FontFamily = new FontFamily("Courier New");
            paragraph.FontSize = 10;
            paragraph.Margin = new Thickness(0);
            paragraph.Inlines.Add(new Run(this.textToPrint));

            flowDocument.FontSize = 10;
            flowDocument.Blocks.Add(paragraph);

            var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
            printDialog.PrintDocument(paginator, "Chit");
        }

This works good for printing stuff with narrow width. But when I try to print a long string, it all gets stuffed in a small area:

enter image description here

I checked dimensions in the print dialog's PrintTicket and in the paginator, and they seem to be okay:

enter image description here

So, what is causing this problem and how can I fix it?

like image 241
Gigi Avatar asked Jul 05 '16 21:07

Gigi


1 Answers

This is some code I use

flowDocument.PagePadding = new Thickness(standardThickness);
flowDocument.ColumnGap = 0;
flowDocument.ColumnWidth = printDialog.PrintableAreaWidth;

You need to tell the flowdocument it is one column and tell the flowdocument the width of the printer.

like image 73
paparazzo Avatar answered Nov 20 '22 12:11

paparazzo