How to start Header from a later page?

Using mlreportgen.dom.PDFPageHeader to generate the header, works fine.
However, the first two pages are different and don't need the header.
How to start Header from page 3 or a later page?
Thanks.

 채택된 답변

Rahul Singhal
Rahul Singhal 2020년 10월 9일

0 개 추천

Hi John,
For a PDF Page layout, you can define upto 3 types of page headers: one for first page, one for even pages, and one for odd pages. See https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.pdfpagelayout-class.html#bu6wf3m-1-PageHeaders
PDFPageHeader class has a PageType property which defines the type of pages that header appears on.
Thanks,
Rahul

댓글 수: 5

John
John 2020년 10월 9일
Hi, Rahul:
Yes, but the purpose is to start the header (or footer) from the page-#3 or page-#n.
If this cannot be down, then we can generate "one report" without the header (or footer), one with it.
Then the question becomes: "How to combine two PDF reports into one single report with Matlab script?"
Thanks.
Rahul Singhal
Rahul Singhal 2020년 10월 9일
편집: Rahul Singhal 2020년 10월 9일
Hi John,
You do not have to create multiple reports, but you can add multiple layouts to the same report.
So, first add a layout which does not define any headers and footers and then add content for those N pages. This will make sure that these N pages won't have headers and footers. After this you can add another layout object which defines headers and footers and then add your rest of the content. This will make sure that all the following pages will have headers and footers.
Thanks,
Rahul
John
John 2020년 10월 9일
Hi, Rahul:
I did so (maybe not right) but the result is the same. Can you make a sinple example?
Greatly appreciated!
Thanks.
Hi John,
Please find below a sample script that adds first 5 pages without a header and next 5 with header.
import mlreportgen.dom.*;
% Create a PDF report
d = Document("MyReport","pdf");
open(d);
% The default layout does not define headers and footers, so directly
% adding the content to the report. If you wish, you can also create a new
% layout object with any custom settings and add that to the report.
for i=1:5
content = strcat("Page without header: ",num2str(i)," of 5");
p = Paragraph(content);
p.Style = [p.Style {PageBreakBefore}];
append(d,p);
end
% Define a new PDF page layout with header and add it to the report
pageLayoutWithHeader = PDFPageLayout();
header = PDFPageHeader();
p = Paragraph("My Header");
p.Style = [p.Style, {HAlign("center"), Bold(true), FontSize("12pt")}];
append(header, p);
pageLayoutWithHeader.PageHeaders = header;
append(d,pageLayoutWithHeader);
% Add the content that should go in the new layout with header
for i=1:5
content = strcat("Page with header: ",num2str(i)," of 5");
p = Paragraph(content);
p.Style = [p.Style {PageBreakBefore}];
append(d,p);
end
% Close and view the report
close(d);
rptview(d);
Thanks,
Rahul
John
John 2020년 10월 9일
Thank you, Rahul!
By editing my existing script which has slightly different style, I learned more about the pagelayout, margin, footer, header, etc...
Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2019b

질문:

2020년 10월 8일

댓글:

2020년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by