I was looking to import RTF into a streaming document, stubbornly for automatic printing purposes; after thousands of uses, using FlowDocument seemed to be the right approach. RTF generally works for me, but the footers disappear when loading RTF in a FlowDocument.
RTF was generated in Word, and when loading on Wordpad, the footers are visible, so I can only assume that I am loading the document incorrectly, or it is a problem with the default installer, or possibly both.
This is what I have so far that downloads the file and prints:
[STAThread]
public static int Main(string[] args)
{
var documentPath = @"C:\temp\Example.rtf";
var fileStream = File.Open(documentPath, FileMode.Open, FileAccess.Read, FileShare.Read);
var flowDocument = new FlowDocument();
TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
textRange.Load(fileStream, DataFormats.Rtf);
flowDocument.ColumnWidth = double.PositiveInfinity;
var t = new Thickness(72);
flowDocument.PagePadding = t;
var queue = LocalPrintServer.GetDefaultPrintQueue();
var capa = queue.GetPrintCapabilities();
var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
paginator.PageSize = new Size(capa.OrientedPageMediaWidth.Value, capa.OrientedPageMediaHeight.Value);
var writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(queue);
writer.Write(paginator);
return 0;
}
... , . , (, , FlowDocument) - , , TextRange, FlowDocument; , paginator.
- , - Google "RTF footer import flowdocument paginator" ( ) () - . , , SO, / RTF.