Add image in the header of the report

18 ビュー (過去 30 日間)
Jack Arnoldi
Jack Arnoldi 2019 年 7 月 2 日
コメント済み: farzad 2020 年 5 月 22 日
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!

回答 (1 件)

Mary Abbott
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
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
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 ExchangeImages, Figures, Axes, Equations, MATLAB Code, and MATLAB Variables についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by