Conversation
|
@liborm85 could you help to review this PR? thanks |
|
Hi @liborm85 , will this PR be reviewed anytime soon (I will work on any feedback)? If not, I might consider to fork the library for now because I need this faeture for my project. |
|
I tried it with text, and it works correctly there. But there’s a problem with tables, try tables example with: pageMargins: function(currentPage, pageCount, pageSize) {
return {
left: (currentPage % 2 === 0) ? 100 : 20,
top: 20,
right: (currentPage % 2 === 0) ? 20 : 100,
bottom: 20
};
},and see pdf document pages. |
|
I added example to PR 9a0df24 and problem is on page 8 in table with headerRows: |
|
yes thank you @liborm85 , i'll try to spare my time for this pr. Acknowledged the current issue with tables, that's why I didn't nudge you yet 🙏 |
d911bad to
87c4c35
Compare
|
Hi @liborm85 , I fixed all the issues. Sorry I need to reset hard some of the commits to avoid making the commits unclean, since I did a lot of changes. But i keep your example file and suggestions. Also I added log warn and examples on the paradox that would cause infinite loop when applying margin in a non divergent way (prevented by the max loop guard). Here's the regression tests I use to verify my work: Let me know anything else I can help if there is any. Otherwise, thank you 🙏 |
|
By the way, seems like there's another issue unrelated to this changes, which is spotted in the example DynamicPageMargins. When column in a table expanded multiple pages, seems the text in the next column in the table is not written yet until the text in prev column is finished processed. It caused big spaces on top of the column. i verified this is not related to the changes by checking out master and run the same example, it produces same output. |

This is an approach to solve the problem when we want to use footer/header in one page only (first page only for header, and last page only for footer). Currently, we have to add page margin (top for header, or bottom for footer) and it will be applied to every page, though we only want for one page only.
With this approach, for footer for example, we will want to conditionally add page margin bottom if last page only. Code:
This is not very easy, because we need pageCount, but pageCount only available once everything is rendered. And adding page margin requires rerendering because it can change the layout. So my approach is to follow page break functionality. In the first pass, the pageCount would be 0, after that pageCount would be filled, and the dynamic page margin condition would execute. If we found that there's more page (due to the page margin that push down the content), then we do additional rerendering until the loop stops itself (pagesCount === result.pages.length).
Actually it can cause infinite loop. For that to happen, the margin function must create a paradox where:
Assuming N pages → produces M pages
Assuming M pages → produces N pages back again
Forever bouncing between N and M.
This can be introduced if we're using odd/even condition, for example. If odd, do large margin, if even, do small margin. That is why I limit the iteration until 10 to avoid this.
Another approach, we can further restrict by only adding parameter "isFirstPage" and "isLastPage". But this is the approach I choose to give flexibility, since technically user should know what are they doing and we can document this the doc.
Let me know what do you think 🙏 .
Image below is my testing: left is using the dynamic page margin, and I successfully applied the page margin bottom for last page only.
