//----< WPF text printing is based on FlowDocuments >-------------- private void printFlowDocument(FlowDocument fd, PrintDialogInfo pi) { IDocumentPaginatorSource idoc = fd as IDocumentPaginatorSource; fd.FontFamily = new System.Windows.Media.FontFamily("Consolas"); fd.FontSize = 12.0; fd.LineStackingStrategy = LineStackingStrategy.BlockLineHeight; // enable reducing line height fd.LineHeight = 8; fd.PageHeight = pi.height; fd.PageWidth = pi.width; fd.ColumnGap = 0; fd.PagePadding = new Thickness(75, 75, 75, 100); fd.ColumnWidth = (fd.PageWidth - fd.ColumnGap - fd.PagePadding.Left - fd.PagePadding.Right); // Can't pass FlowDocuments between threads, so we have to serialize stream = new MemoryStream(); System.Windows.Markup.XamlWriter.Save(fd, stream); stream.Position = 0; Action act = () => printFromStream(stream); Dispatcher.Invoke(act); }
//----< WPF text printing is based on FlowDocuments >-------------- private void printFlowDocument(FlowDocument fd, PrintDialogInfo pi) { IDocumentPaginatorSource idoc = fd as IDocumentPaginatorSource; fd.FontFamily = new System.Windows.Media.FontFamily("Consolas"); fd.FontSize = 12.0; fd.LineStackingStrategy = LineStackingStrategy.BlockLineHeight; // enable reducing line height fd.LineHeight = 8; fd.PageHeight = pi.height; fd.PageWidth = pi.width; fd.ColumnGap = 0; fd.PagePadding = new Thickness(75, 75, 75, 100); fd.ColumnWidth = (fd.PageWidth - fd.ColumnGap - fd.PagePadding.Left - fd.PagePadding.Right); // Can't pass FlowDocuments between threads, so we have to serialize stream = new MemoryStream(); System.Windows.Markup.XamlWriter.Save(fd, stream); stream.Position = 0; Action act = () => printFromStream(stream); Dispatcher.Invoke(act); }