Skip to content

Commit

Permalink
support inherit page definition
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Nov 3, 2024
1 parent 1cec32b commit d9afdc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Binary file modified examples/pdfs/sections.pdf
Binary file not shown.
17 changes: 16 additions & 1 deletion examples/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,26 @@ var docDefinition = {
{
pageSize: 'A6',
pageOrientation: 'landscape',
pageMargins: 5,
pageMargins: 10,
section: [
'SECTION 5',
'Text in section as A6 landscape page with margin.'
]
},
{
pageSize: 'inherit',
pageOrientation: 'inherit',
pageMargins: 'inherit',
section: [
'SECTION 7',
'Text in section with page definition as previous page. Page size, orientation and margins are inherited.'
]
},
{
section: [
'SECTION 8',
'Text in section with page definition as defined in document.'
]
}
]
};
Expand Down
12 changes: 11 additions & 1 deletion src/LayoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,17 @@ class LayoutBuilder {
let page = this.writer.context().getCurrentPage();
// TODO: background
if (!page || (page && page.items.length)) { // move to new empty page
// TODO: property for inherit page size and margin from before section
// page definition inherit from current page
if (sectionNode.pageSize === 'inherit') {
sectionNode.pageSize = page ? {width: page.pageSize.width, height: page.pageSize.height} : undefined;
}
if (sectionNode.pageOrientation === 'inherit') {
sectionNode.pageOrientation = page ? page.pageSize.orientation : undefined;
}
if (sectionNode.pageMargins === 'inherit') {
sectionNode.pageMargins = page ? page.pageMargins : undefined;
}

this.writer.addPage(
sectionNode.pageSize || this.pageSize,
sectionNode.pageOrientation,
Expand Down

0 comments on commit d9afdc9

Please sign in to comment.