How can I create a List of Figures in a pdf report created with Report Generator?

2 views (last 30 days)
Hello,
In a .pdf report, created with mlreportgen.dom package, the Table of Contents (TOC) and a series of chapters, section and Figures with caption have been implemented as shown here: https://it.mathworks.com/help/rptgen/ug/number-section-headings-table-titles-and-figure-captions-programmatically.html
I would like to create (after the Table of Contents) a list indicating at each row: figure number, its caption and page number. It is usually named "List of Figures" in a report (e.g. Figure 1.1 Caption of the figure........page).
Practically, I would need something analogous to mlreportgen.dom.TOC class, but instead of operating on headings(chapters/sections) it should works on images-caption.
Thank you very much for any advice/tip
Best regards

Answers (1)

Rahul Singhal
Rahul Singhal on 15 Jun 2020
Hi Alessio,
Considering the exact use case you mentioned, the team plans to add new APIs in R2020b, that will automatically create a list of figures, tables, and captions, and then can be added to a report in the same way as TOC.
Curently, you can use the below helper function to add a list of figures/tables in a DOCX (not PDF) report:
function obj = mkto_t_f(stream_name)
import mlreportgen.dom.*
tof = [
'<w:p>' ...
'<w:fldSimple w:instr=" TOC \\h \\z \\c &quot;%s&quot; ">' ...
'<w:r>' ...
'<w:rPr>' ...
'<w:b/>' ...
'<w:bCs/>' ...
'<w:noProof/>' ...
'</w:rPr>' ...
'<w:t>No table of figures entries found.</w:t>' ...
'</w:r>' ...
'</w:fldSimple>' ...
'</w:p>' ...
];
obj = RawText(sprintf(tof, stream_name), 'docx');
end
Using the helper function mentioned above, adding the list of figures/tables to a DOCX report.
% Insert a List of Figures in DOCX report
append(d, mkto_t_f('figure'));
% Insert a List of Tables in DOCX report
append(d, mkto_t_f('table'));
If you really want it in PDF report, you can programmatically convert the DOCX report into PDF as mentioned below:
docview(d.OutputPath, 'updatedocxfields', 'convertdocxtopdf');
Thanks,
Rahul

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!