Add image in the header of the report
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Mary Abbott
le 2 Juil 2019
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 commentaires
Mary Abbott
le 28 Jan 2020
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
le 22 Mai 2020
dear Marry, may you please take a look at my question here ? I got unresolvable problem with compiling my app with report generator
Voir également
Catégories
En savoir plus sur Images, Figures, Axes, Equations, MATLAB Code, and MATLAB Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!