Text Document printout mode

The Text Document mode allows you to render and print multi-page rich texts based on HTML and QTextDocument. The text source can be a file or any data source, so the text can be static, dynamic, or even a static template filled with dynamic data. In this mode, the report engine collects the HTML content of the report items into one text document, which is then broken into pages by the Qt rich text engine. The result is a multi-page HTML text, correctly broken into pages and ready for printing. In Text Document mode, the pagecount system variable can be used without any additional setting, because the number of pages is known before the pages are rendered.

Steps of usage

To create a text document printout report in the Designer:

  • Select Report  Report and page settings…​. In the dialog that appears, set the Report type combo box on the General tab to Text document.

  • Add a Text item to the Detail section. Set the text’s properties in its property dialog. The text may come from any source, as usual.

  • Specify the report’s page header and footer, if needed. They are printed on every page.

How the document is built

  • The texts of the report header, the report footer, and the detail sections are joined into one document, in this order. If a detail has a data source, its content is added once for every data record.

  • Besides Text items, Image items are also included in the document. Other item types are ignored in the detail sections.

  • The print-when expressions of the sections and items are evaluated as usual.

  • The horizontal position and the width of the first Text item (if they differ from the defaults) determine the left margin and the width of the printed text block. The height of the text block is the page height minus the margins, the page header, and the page footer.

The text of a Text item can also come from your application: set the source type of the item to Internal document and pass your QTextDocument object to the report with the NCReport::setTextDocument() function before running the report.

Text Document printout report example

To see how it works, try the textdocument_printout.xml demo report. It prints a long Qt class documentation HTML file.