I am create a UWP/C# desktop application that needs to include reports. I am familiar using the macOS CoreText and CGContext to draw on screen, print or generate PDF documents. I can't seem to find anything similar for UWP. The Microsoft samples for UWP seem to use RichTextBlock and some other interesting approaches, but these seem to rely on the automatic formatting and text flow built in to the RichTextBlock so I don't seem to have control over basic things like starting a new page or being able to check the layout to keep paragraphs together.
Can anyone point me in the right direction for how to do this. Some of the basic requirements are:
- text formatting - bold, underline, font size and weight, etc.
- paragraph styles - indents, bullet, wrapping, etc.
- page headers and footers
- keep paragraphs together e.g. headings with following paragraphs.
- Output in PDF or print.
Happy to use the windows print system for generating the PDF as it seems to convert to vector PDF which is fine although it seems under UWP it's not possible to programatically set all the print options and some user intervention is required - will live with that for now.
EDIT
I don't want to edit rich text, I want to generate a report from content in a database and need to be able to do things like force a page break for new sections, keep headers on the same page as the following paragraph, and so on.
With CoreText you can format a paragraph and ask CoreText API how much space it needs to render the text, you can then decide if you have enough space left on the page to print the paragraph or to start a new page.
It's not clear to me how one would achieve the same thing using the UWP APIs - but it must be possible.
For example if it was possible to set the width of a RichTextBlock and ask it how much height it needs to render it's content that would be great.
RichTextBlockOverflow
class that used to create advanced page layouts, such as multi-column text. The content for a RichTextBlockOverflow element always comes from a RichTextBlock element.. – Nico Zhu - MSFT