Printing RTF with headers and footers - FlowDocument or something else?

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);

    // Load the RTF into the flow document
    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; // Page margin

    // Get printer
    var queue = LocalPrintServer.GetDefaultPrintQueue();
    var capa = queue.GetPrintCapabilities();

    // Configure paginator
    var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
    paginator.PageSize = new Size(capa.OrientedPageMediaWidth.Value, capa.OrientedPageMediaHeight.Value);

    // ...and print.
    var writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(queue);
    writer.Write(paginator);

    return 0;
}

... , . , (, , FlowDocument) - , , TextRange, FlowDocument; , paginator.

- , - Google "RTF footer import flowdocument paginator" ( ) () - . , , SO, / RTF.

+4
2

- MSDN, , . DocumentPaginator . , . , .

+1

Source: https://habr.com/ru/post/1527854/


All Articles