Add image in the header of the report
18 次查看(过去 30 天)
显示 更早的评论
I am trying to put a simple image in the header of my report. I am not using the report generator app but just coding.
I don't understand how to construct a header in this report generator. Do I always have to go through a template?
Can someone give me links to a tutorial or documentation that will give me hints on how to construct a header?
Thank you in advance!
0 个评论
回答(1 个)
Mary Abbott
2019-7-2
Hello,
Templates are not required for constructing a header. To create a header in a report programmatically, you can add a header object to the report's page layout. The following is an example for PDF reports. If you are creating a Word report instead, change the report type to 'docx' and create a DOCXPageHeader instead of a PDFPageHeader:
import mlreportgen.dom.*
import mlreportgen.report.*
rpt = Report('exampleReport', 'pdf') % Create an mlreportgen.report.Report object
% Create a sample image
im = Image(which('peppers.png'));
im.Width = '0.75in';
im.Height = '0.75in';
% Construct the header
header = PDFPageHeader();
append(header, im);
% Get the report's page layout and set header
layout = getReportLayout(rpt);
layout.PageHeaders = header;
% (optional) Adjust the space for the header and top page margin
layout.PageMargins.Header = '1in';
layout.PageMargins.Top = '0.5in';
% Add sample content
p = Paragraph('sample text');
add(rpt, p);
% Close and view report
close(rpt);
rptview(rpt)
If you would like to use a template, or if you are using a DOM API Document object instead of the newer Report API Report object, please see the following link:
9 个评论
Mary Abbott
2020-1-28
Hi Varun,
You can use the text-align style in PDF templates to align the img element. For example:
<img height=".75in" width=".75in" style="text-align:center;" src="./images/peppers.png"/>
You can also create a style in the template's style sheet. More information about the available styles for PDF templates is here:
I'm not sure I understand the issue you describe with the two chapter titles. I suggest reaching out to technical support, as they will be able to look into the issue more.
farzad
2020-5-22
dear Marry, may you please take a look at my question here ? I got unresolvable problem with compiling my app with report generator
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Images, Figures, Axes, Equations, MATLAB Code, and MATLAB Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!