Pete,
I cannot thank you enough for your help.
Using Visual Studio 2022 your code would not build due to type conversion errors.
After some fiddling I got a working version which I include below.
For some strange reason, when I pasted to this solution box, some lines were red underlined.
Sincerely,
Tony (email removed)
using System.Windows.Controls;
using System.Windows.Documents;
using System.IO;
using System.Windows;
namespace Streaming
{
internal class PrintFactory
{
public string textfilename;
public string textitself;
public string texttitle;
public PrintFactory(string textfilename, string texttitle)
{
this.textfilename = textfilename;
this.textitself = File.ReadAllText(textfilename);
this.texttitle = texttitle;
}
public void PrintText()
{
PrintDialog printDialog = new PrintDialog();
if ((bool)printDialog.ShowDialog().GetValueOrDefault())
{
FlowDocument flowDocument = new FlowDocument();
foreach (string line in textitself.Split('\n'))
{
Paragraph myParagraph = new Paragraph();
myParagraph.Margin = new Thickness(5);
myParagraph.Inlines.Add(new Run(line));
flowDocument.Blocks.Add(myParagraph);
}
DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
printDialog.PrintDocument(paginator, texttitle );
}
}
}
}