MATLAB: How to add custom text to a footer in a generated report

customfootergeneratorheaderMATLABpagereportstringtext;

I am generating my report programmatically. It already has a page footer containing the relevant page number, but how do I include an additional string in the page footer? For example, I would like the word "UNCLASSIFIED" centered at the bottom of each page.

Best Answer

To add custom text to a footer in your report, you can work with the 'DOCXPageFooter' class:
Documentation Page:
Example of making a footer:
When creating a page footer, you can first specify which pages you would like it to appear on (first page only, even pages, odd pages, or all pages). Then, you can append different DOM objects to the footer, such as a page number or a paragraph.
The following code is an adaptation of the example linked above. This code demonstrates how to add a paragraph with custom text to a footer which already includes the page number:
import mlreportgen.dom.*;
d = Document('mydoc','docx');
open(d);
% Create page footer object
myfooter = DOCXPageFooter();
d.CurrentPageLayout.PageFooters = [myfooter];
% Add page number to footer
pageNum = Page();
append(d.CurrentPageLayout.PageFooters(1), pageNum);
% Add custom text to footer
txt = Paragraph('My custom text');
txt.HAlign = 'center';
append(d.CurrentPageLayout.PageFooters(1),txt);
% Create several pages.
p = Paragraph('Title page');
append(d,p);
p = Paragraph('Another page');
p.Style = {PageBreakBefore(true)};
append(d,p);
append(d,clone(p));
append(d,clone(p));
close(d);
rptview(d.OutputPath);