diff --git a/demos/modules/demo_table.mjs b/demos/modules/demo_table.mjs index a3942386..5943100d 100644 --- a/demos/modules/demo_table.mjs +++ b/demos/modules/demo_table.mjs @@ -3,8 +3,8 @@ * AUTH: Brent Ely (https://github.com/gitbrent/) * DESC: Common test/demo slides for all library features * DEPS: Used by various demos (./demos/browser, ./demos/node, etc.) - * VER.: 3.10.0 - * BLD.: 20220220 + * VER.: 3.12.0 + * BLD.: 20230207 */ import { @@ -594,7 +594,7 @@ function genSlide07(pptx) { // EX-3: "Master Page with Auto-Paging" { - slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_PLAIN" }); + slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER" }); slide.addText( [ { text: "Table Examples: ", options: DEMO_TITLE_TEXT }, @@ -602,7 +602,11 @@ function genSlide07(pptx) { ], { x: 0.5, y: 0.13, w: "90%" } ); + slide.addText("Auto-Paging table", { placeholder: "footer" }); slide.addTable(arrRows, { x: 1.0, y: 0.6, colW: [0.75, 1.75, 7], margin: 0.05, border: { color: "CFCFCF" }, autoPage: true }); + // HOWTO: In cases where you want to add custom text, placeholders, etc. to slidemasters, a reference to these slide(s) is needed + // HOWTO: Use the `newAutoPagedSlides` to access references (see [Issue #625](https://github.com/gitbrent/PptxGenJS/issues/625)) + slide.newAutoPagedSlides.forEach((slide) => slide.addText("Auto-Paging table continued...", { placeholder: "footer" })); } // EX-4: "Auto-Paging Disabled" diff --git a/demos/modules/masters.mjs b/demos/modules/masters.mjs index 164a9083..e2c4d6e3 100644 --- a/demos/modules/masters.mjs +++ b/demos/modules/masters.mjs @@ -62,6 +62,24 @@ export function createMasterSlides(pptx) { slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" }, }); + // MASTER_AUTO_PAGE_TABLE_PLACEHOLDER + pptx.defineSlideMaster({ + title: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER", + background: { fill: "F1F1F1" }, + margin: [0.5, 0.25, 1.0, 0.25], + objects: [ + { rect: { x: 0.0, y: 6.9, w: "100%", h: 0.6, fill: { color: "003b75" } } }, + { image: { x: 11.45, y: 5.95, w: 1.67, h: 0.75, data: STARLABS_LOGO_SM } }, + { + placeholder: { + options: { name: "footer", x: 0, y: 6.9, w: "100%", h: 0.6, align: "center", valign: "middle", color: "FFFFFF", fontSize: 12 }, + text: "(footer placeholder)", + }, + }, + ], + slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" }, + }); + // MASTER_SLIDE (MASTER_PLACEHOLDER) pptx.defineSlideMaster({ title: "MASTER_SLIDE", diff --git a/src/gen-objects.ts b/src/gen-objects.ts index ae4fe69a..f0c86d5c 100644 --- a/src/gen-objects.ts +++ b/src/gen-objects.ts @@ -728,7 +728,7 @@ export function addTableDefinition ( presLayout: PresLayout, addSlide: (options?: AddSlideProps) => PresSlide, getSlide: (slideNumber: number) => PresSlide -): void { +): PresSlide[] { const slides: PresSlide[] = [target] // Create array of Slides as more may be added by auto-paging const opt: TableProps = options && typeof options === 'object' ? options : {} opt.objectName = opt.objectName ? encodeXmlEntities(opt.objectName) : `Table ${target._slideObjects.filter(obj => obj._type === SLIDE_OBJECT_TYPES.table).length}` @@ -932,6 +932,9 @@ export function addTableDefinition ( }) }) + // If autoPage = true, we need to return references to newly created slides if any + const newAutoPagedSlides: PresSlide[] = [] + // STEP 6: Auto-Paging: (via {options} and used internally) // (used internally by `tableToSlides()` to not engage recursion - we've already paged the table data, just add this one) if (opt && !opt.autoPage) { @@ -966,9 +969,13 @@ export function addTableDefinition ( // Add rows to new slide newSlide.addTable(slide.rows, Object.assign({}, opt)) + + // Add reference to the new slide so it can be returned, but don't add the first one because the user already has a reference to that one. + if (idx > 0) newAutoPagedSlides.push(newSlide) } }) } + return newAutoPagedSlides } /** diff --git a/src/pptxgen.ts b/src/pptxgen.ts index 23bf0e6a..5cdd8422 100644 --- a/src/pptxgen.ts +++ b/src/pptxgen.ts @@ -97,7 +97,7 @@ import * as genMedia from './gen-media' import * as genTable from './gen-tables' import * as genXml from './gen-xml' -const VERSION = '3.12.0-beta-20230207-2320' +const VERSION = '3.12.0-beta-20230207-2340' export default class PptxGenJS implements IPresentationProps { // Property getters/setters diff --git a/src/slide.ts b/src/slide.ts index d92b6850..a46f1eaf 100644 --- a/src/slide.ts +++ b/src/slide.ts @@ -45,6 +45,7 @@ export default class Slide { public _slideNum: number public _slideNumberProps: SlideNumberProps public _slideObjects: ISlideObject[] + public _newAutoPagedSlides: PresSlide[] constructor (params: { addSlide: (options?: AddSlideProps) => PresSlide @@ -152,6 +153,10 @@ export default class Slide { return this._slideNumberProps } + public get newAutoPagedSlides(): PresSlide[] { + return this._newAutoPagedSlides + } + /** * Add chart to Slide * @param {CHART_NAME|IChartMulti[]} type - chart type @@ -223,7 +228,7 @@ export default class Slide { */ addTable (tableRows: TableRow[], options?: TableProps): Slide { // FUTURE: we pass `this` - we dont need to pass layouts - they can be read from this! - genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide) + this._newAutoPagedSlides = genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide) return this } diff --git a/types/index.d.ts b/types/index.d.ts index c91ce11b..596f63ab 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2533,6 +2533,10 @@ declare namespace PptxGenJS { * Slide number options */ slideNumber: SlideNumberProps + /** + * New slides added by an auto paged table + */ + newAutoPagedSlides: PresSlide[] /** * Add chart to Slide * @param {CHART_NAME|IChartMulti[]} type - chart type