Report generator page break style not working

I'm having trouble with page breaks in pdf report generator.
Here is my code:
% Make layout tables
lot1 = Table({tableRun1, '',tableRun2});
lot1.Style = {Width('100%'), Border('solid','black','1px'), ...
ColSep('solid','black','1px'), ...
RowSep('solid','black','1px'), ...
ResizeToFitContents(true)};
lot2 = Table({tableExport1, '',tableExport2});
lot2.Style = [{Width('100%'), Border('solid','black','1px'), ...
ColSep('solid','black','1px'), ...
RowSep('solid','black','1px'), ...
ResizeToFitContents(true)},{PageBreakBefore(1)}];
% Add content to report
add(rpt, lot1);
add(rpt, lot2);
Below is an image of what I'm getting.
The grey is lot1, the orange is lot2, which is splitting between two pages.
Intent is for lot2 to start on the following page. It was working previously until I increased the length of the first element of lot2 by one row.
Many thanks in advance
John

1 Comment

In case anyone else has this problem, I found that increasing the margins from 1cm to 2cm rectified the problem and lot2 goes onto the next page as intended.
Still none the wiser as to why increasing the length of tableExport1 from 4 rows to 5 stops the page break from working with the 1cm margins though.

Sign in to comment.

 Accepted Answer

Hi John,
I understand that you are facing issues while adding page breaks in report generator using MATLAB.
I have reproduced the issue at my end using MATLAB R2022b, I discovered that this issue only arises if the combined size of "lot1" and "lot2" exceeds the page size. If the combined size is smaller, the page break functions as expected.
To overcome this issue, I have identified a workaround that works in both cases. Instead of using the "mlreportgen.dom.PageBreakBefore" class, you can use the "mlreportgen.dom.PageBreak" class.
Refer to the below code for the implementation:
% Create a Page Break Object
breakObj = mlreportgen.dom.PageBreak()
% Add content to report
add(rpt, lot1);
add(rpt, breakObj);
add(rpt, lot2);
The documentation of the "mlreportgen.dom.PageBreak" class is available at the link provided below:
I hope this addresses your query.
Best Regards,
Yash

1 Comment

I haven't tested this but sounds like a solution.
Thanks very much

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022b

Asked:

on 15 Sep 2023

Commented:

on 4 Oct 2023

Community Treasure Hunt

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

Start Hunting!