Build folded products and spreads, such as a tri-fold leaflet, a gatefold brochure, a folded card or a photobook spread. This guide shows how a page holds one page slice per panel, how content belongs to a panel, how panels move between pages, and how to export the sheet for print.
The example builds the outside of a tri-fold leaflet with three panels of 99 × 210 mm: the inside flap, the back and the cover. This guide covers:
- How a page with page slices makes a folded product
- Creating the panels and giving one a background
- Finding the panel that owns a block, and the blocks of a panel
- Reordering, hiding, deleting and moving panels
- Exporting the sheet for a printer, and one panel for a preview
- What each error code asks your app to do
How a Folded Product Is Built#
A folded product is one sheet of paper with folds: a tri-fold leaflet, a gatefold brochure, a folded greeting card, a tent card, or a book cover with a spine. A photobook spread works the same way: two facing pages on one sheet.
CE.SDK builds such a product as one page that holds page slices. Each page slice is one panel of the product, such as the cover of a tri-fold. The page places its page slices in reading order along one axis, and the folds lie between them.
page/pageSliceAxissets the axis:Horizontalputs the page slices in a row,Verticalputs them in a column.- The page takes the size of all its page slices together. You size the panels, not the page.
- A page slice holds no children. Text, images and shapes stay children of the page, in the coordinates of the page.
- The page slice under the center of a block owns that block. The owner decides where the block belongs, for example when you hide or move a panel.
- Page slices work in a design scene only. A video scene refuses them.
In the CE.SDK web editor, a page with page slices shows as a spread, and each page slice shows as a page of that spread.
A scene or an archive with page slices loads only in CE.SDK 1.87 and later. Versions 1.85 and 1.86 return an error, and 1.84 and earlier crash. Update every app and server that opens your scenes before your users save page slices, for example a mobile app or a render server.
Create a Tri-Fold Leaflet#
Create a design scene, set its design unit to millimeters, and add a page. The page gets a 3 mm bleed on each side.
engine.scene.create('VerticalStack');engine.scene.setDesignUnit('Millimeter');const [stack] = engine.block.findByType('stack');
const page = engine.block.create('page');engine.block.appendChild(stack, page);
// A 3 mm bleed on every side of the sheetengine.block.setBool(page, 'page/marginEnabled', true);for (const side of ['top', 'bottom', 'left', 'right']) { engine.block.setFloat(page, `page/margin/${side}`, 3);}Create one page slice per panel. Give each page slice its width, height and name, then append it to the page. The page now measures 297 × 210 mm.
// The outside of a tri-fold: the inside flap, the back and the coverconst panelNames = ['Inside Flap', 'Back', 'Cover'];const panels: DesignBlockId[] = panelNames.map((panelName) => { const panel = engine.block.create('pageSlice'); // Size the page slice before it joins the page. engine.block.setWidth(panel, 99); engine.block.setHeight(panel, 210); engine.block.setName(panel, panelName); engine.block.appendChild(page, panel); return panel;});const [flap, , cover] = panels;Size each page slice before you append it. A new page slice is 100 × 100 in the design unit of the scene, and the first page slice that you append gives the page its size. When you size the page slice first, the page takes the right size at once.
These rules apply to the size of a page slice:
- A page slice and its page take only an absolute width and height. Another size mode fails.
- A width, height or scale of 0 or less on a page slice fails with
BLOCK.PAGE_SLICE_SIZE_INVALID. - In a row, all page slices share one height.
setHeighton one page slice sets the height of every page slice and of the page. In a column, all page slices share one width. setWidthon the page goes to the last page slice of a row, and to every page slice of a column.setHeighton the page works the other way round. A page slice that this shrinks stops at 25 pixels, which is about 2.1 mm at 300 DPI. The page can then end up larger than you asked.- The page sets the position of each page slice. A call that sets, aligns or distributes the position of a page slice fails.
- A switch of
page/pageSliceAxiskeeps the size of each page slice.
After you change a page slice, the engine lays out the page on its next update. In the browser, that is the next frame. Until then, a size or position that you read can be the old value.
Give a Panel a Background#
A new page slice has its fill turned off. setFill on a page slice sets the fill and turns it on, so the color shows at once.
const coverFill = engine.block.createFill('color');engine.block.setColor(coverFill, 'fill/color/value', { r: 0.13, g: 0.36, b: 0.6, a: 1});// setFill on a page slice also turns its fill on.engine.block.setFill(cover, coverFill);Add Content to the Panels#
// Content is a child of the page, in the coordinates of the page.const title = engine.block.create('text');engine.block.appendChild(page, title);engine.block.replaceText(title, 'Summer Workshops');engine.block.setTextFontSize(title, 28, { unit: 'Point' });engine.block.setTextColor(title, { r: 1, g: 1, b: 1, a: 1 });engine.block.setWidth(title, 79);engine.block.setHeightMode(title, 'Auto');engine.block.setPositionX(title, 208);engine.block.setPositionY(title, 30);
const flapNote = engine.block.create('graphic');engine.block.setShape(flapNote, engine.block.createShape('rect'));const noteFill = engine.block.createFill('color');engine.block.setColor(noteFill, 'fill/color/value', { r: 0.95, g: 0.75, b: 0.2, a: 1});engine.block.setFill(flapNote, noteFill);engine.block.appendChild(page, flapNote);engine.block.setWidth(flapNote, 79);engine.block.setHeight(flapNote, 60);engine.block.setPositionX(flapNote, 10);engine.block.setPositionY(flapNote, 140);Content is a child of the page, not of a page slice. Place each block in the coordinates of the whole sheet. In the tri-fold earlier in this guide, the cover starts at x = 198 mm, so the title sits at x = 208 mm.
A block sized in percent of the page follows a later setWidth on the page only while the page holds no page slices. On a page with page slices, give the block an absolute size.
Two settings of a page slice act on the blocks that it owns:
setClippedon a page slice cuts the blocks that it owns at the folds and at the page edges with their bleed, also when the page does not clip. A click beside the page still selects these blocks, because only the folds cut a click.- A movement constraint set on a page slice applies to the blocks whose center the page slice holds. Its edges to the other page slices act as page edges for them.
Find the Panel That Owns a Block#
getOwningPageSlice returns the page slice that owns a block. To get the blocks of one panel, filter the children of the page by their owner.
// The page slice under the center of a block owns it.const titleOwner = engine.block.getOwningPageSlice(title);if (titleOwner !== null) { console.log('The title is on:', engine.block.getName(titleOwner));}
// The blocks of one panel: filter the children of the page.const coverBlocks = engine.block .getChildren(page) .filter((child) => engine.block.getOwningPageSlice(child) === cover);console.log('Blocks on the cover:', coverBlocks.length);getPageSlices returns the panels in reading order.
// Reading order, hidden page slices tooconst readingOrder = engine.block .getPageSlices(page) .map((panel) => engine.block.getName(panel));console.log('Panels in reading order:', readingOrder.join(', '));getOwningPageSlice follows these rules:
- The page slice under the center of a block owns the block.
- A block whose center is exactly on a fold belongs to the earlier page slice.
- A block outside the page belongs to the nearest page slice.
- A block in a group belongs where its group does. The group counts as one block.
- The call returns no page slice for a block that is not on a page with page slices. It also returns none for a page or a page slice.
- An invalid block id fails the call.
No call lists the blocks of one page slice. Filter the children of the page by their owner, as the example does. getChildren also lists the page slices themselves, and the filter leaves them out, because a page slice has no owner.
getPageSlices lists the page slices of a page in reading order. Hidden page slices are in the list too. A block without page slices gives an empty list.
Reorder, Duplicate, Hide and Delete Panels#
A page slice takes its blocks along when you change it:
- Reorder.
insertChildwith the page as the parent moves a page slice to another place in the reading order. The blocks that it owns move with it. - Duplicate.
duplicateputs the copy right after the original and copies the blocks that the page slice owns. - Delete.
destroydeletes the page slice and the blocks that it owns. This also holds for the last page slice: the page then becomes an empty page of the same size. To keep the content, move the page slice out to its own page first. - Hide.
setVisible(pageSlice, false)hides the page slice and the blocks that it owns, also where they reach into a neighbour. They show neither on the canvas nor in an export of the page. The page slice keeps its room on the sheet. An export of the hidden page slice itself still shows it. To hide only the background of a panel, turn its fill off withsetFillEnabledinstead. - Select. A page slice and its page are never selected together. Selecting one deselects the other.
- Show one panel. In single page mode,
setCurrentPagestakes page slices too. The canvas then shows the page, but only inside the page slice.
A page slice refuses the calls that it cannot use. setAlwaysOnTop and setAlwaysOnBottom fail with BLOCK.TYPE_CANNOT_BE_ARRANGED. setBlendMode fails with BLOCK.BLEND_MODE_UNSUPPORTED, and setDuration fails with EDITOR.BLOCK_NO_DURATION_SUPPORT. supportsBlendMode and supportsDuration return false for a page slice.
Move a Panel to Another Page#
The example takes the flap out of the leaflet as a page of its own, then puts it back as the first panel. An addUndoStep call after each move makes it one undo step.
// Take the flap out as its own page, after the leaflet.const flapPage = engine.block.movePageSliceOutOfPage(flap, 1);engine.editor.addUndoStep();
// Put it back as the first panel. The id changes on each move.const flapAgain = engine.block.movePageSliceIntoPage(flapPage, page, 0);engine.editor.addUndoStep();const noteOwner = engine.block.getOwningPageSlice(flapNote);console.log('The note is on the flap again:', noteOwner === flapAgain);Two calls move panels between pages:
movePageSliceOutOfPagemakes a page slice its own page without page slices. Its index is the place of the new page among the pages of the scene, counted before the move. The source page counts too. In the example, index1puts the new page after the leaflet.movePageSliceIntoPagemakes a page, or a page slice of another page, a page slice of a page with page slices. Its index is the place among the page slices of that page, hidden ones too.
Read these rules before you use the moves:
- The content moves along and keeps its block ids.
- A page that becomes a page slice gets a new id, and so does a page slice that becomes a page. Use the id that the call returns. A page slice that moves straight to another page keeps its id.
- The destination of
movePageSliceIntoPagemust already hold page slices. To start a folded product, append page slices to a page, as in the first example. convertSourceToPageacts only when the move leaves one page slice on the source page. That page slice and its content then become the page and its content. The option isfalseby default.- A move records no undo step of its own. Call
addUndoStepafter the move, as after any other edit. An edit and a move then undo together. - A move fails while the engine switches its active history. A failed move changes nothing.
Handle Errors#
A refused call throws an engine error. Check it with isEngineError and branch on its code.
// The scene has one page, so index 9 is a bug in the calling code.try { engine.block.movePageSliceOutOfPage(flapAgain, 9);} catch (error) { if (!isEngineError(error)) throw error; if (error.code !== 'BLOCK.PAGE_SLICE_MOVE_INDEX_INVALID') throw error; console.log('Refused move:', error.code);}Each error code of page slices tells your app what to do next.
A bug in your code. Fix the call, and throw the error again in your app:
BLOCK.PAGE_SLICE_MOVE_INDEX_INVALID: the index is out of range.BLOCK.PAGE_SLICE_PARENT_INVALID: a page slice can only be a child of a page with a rect shape.BLOCK.PAGE_SLICE_IN_VIDEO_SCENE: a video scene takes no page slices.BLOCK.PAGE_SLICE_RESIZE_CONTENT_AWARE: a content-aware resize does not take a page slice. Resize its page instead.BLOCK.PAGE_SLICE_SIZE_MODE_INVALID: a page slice and its page take only an absolute size.BLOCK.PAGE_SLICE_SIZE_INVALID: a page slice needs a width, a height and a scale greater than 0.
The user can act. Tell the user what to do:
BLOCK.PAGE_SLICE_MOVE_MATTE_INVALID: a block and its matte source stay on one page. The user moves both together, then tries again.
Your app can fix it:
BLOCK.PAGE_SLICE_MOVE_INVALID: the blocks cannot take part in this move. A page can lose its page slices while the app runs, so check the destination withgetPageSlicesbefore the move. Any other case is a bug in your code.BLOCK.PAGE_SLICE_MOVE_UNSUPPORTED_PROPERTIES: the move cannot keep a property. The error has four causes:- The page has properties that a page slice cannot hold, such as a rotation, a shadow, an effect, rounded corners or a non-rectangular shape. Reset those properties, then move the page again.
- A page that becomes a page slice, or a page slice that becomes a page, has an animation, or keyframes on a property other than opacity, blend mode or stroke. Remove them, then move again.
- With
convertSourceToPage, the page slice that stays and becomes the page has an animation or keyframes. Remove them, or move without the option. - A transform parent links a block that moves to a block that stays. Remove the link with
setTransformParent, or move both blocks.
BLOCK.OPERATION_PRECONDITION_FAILED: the move cannot run now, or it would put content in the wrong place. The error has three causes:- The engine switches its active history. Wait until the switch ends, then move again.
- The move would put content of the moved page or page slice on another page slice of the destination. Move that content fully inside its page or page slice, or choose another destination.
- A block that stays follows a transform parent that the move shifts to another place. Remove the link with
setTransformParent, then move again.
Export for Print#
The example exports the cover as a PNG, and the whole sheet as a PDF with crop marks and fold marks.
// One panel, with the bleed of the page on all four sidesconst coverImage = await engine.block.export(cover, { mimeType: 'image/png'});
// The whole sheet, as a printer wants a folded leafletconst sheet = await engine.block.export(page, { mimeType: 'application/pdf', exportPdfWithCropMarks: true, exportPdfWithFoldMarks: true});console.log('Cover PNG bytes:', coverImage.size);console.log('Sheet PDF bytes:', sheet.size);A printer wants a folded leaflet as the whole sheet, with bleed and printer’s marks. Export the page, not each page slice. For a two-sided leaflet, make one page for the outside and one for the inside.
exportPdfWithCropMarksdraws the crop marks that show where to cut. Crop marks draw no fold marks.exportPdfWithFoldMarksdraws a pair of fold marks at each fold, outside the bleed. A fold is at the start of each visible page slice that follows another visible page slice. The option isfalseby default.- Set the bleed with
page/marginEnabledand the fourpage/marginproperties of the page. The bleed applies to the outer edges of the sheet.
The export of one page slice gives the part of the page inside that page slice, in any format. It has the bleed of the page on all four sides. At a fold, the bleed shows the content of the page slice beside it. Use it for a thumbnail or a preview of one panel.
exportPdfWithFoldMarks and the other PDF options are described in Export to PDF. There, exportPdfPageSlices gives one PDF page per visible page slice. Use it for previews, proofs and products whose panels print as separate sheets, such as a photobook. A hidden page slice gets no PDF page, and the content that it owns shows on no PDF page.
Titles of Spreads and Panels#
The canvas shows a title above each page. Two string properties of the page set the title text:
page/titleTemplateis the title of a page without page slices and of each page slice, such as"Page {{ubq.page_index}}". On a page with page slices,{{ubq.page_index}}counts the page slices.page/titleTemplateWithPageSlicesis the title of a page with page slices,"Spread {{ubq.page_with_page_slices_index}}"by default. The placeholder{{ubq.page_with_page_slices_index}}counts only the pages with page slices.
The shown title is the template, plus the name of the block when the setting page/title/appendPageName is on. Do not put the name in the template as well, or the title shows the name twice. The setting page/title/showOnPageSlices shows a title above each page slice in place of the title of the page.
Settings That the Scene Does Not Save#
The scene file saves the page slices, their sizes, names, fills and title templates. It does not save these settings of the engine, so set them again after you load a scene:
page/title/showOnPageSlices, which shows a title above each page slice.page/pageSliceGuideColor, the color of the dashed guide between two page slices.- The page slices that single page mode shows with
setCurrentPages.
Folded Products in the Editor#
The advanced editor shows a page with page slices as a spread, and each page slice as a page of that spread. The spread option of the ly.img.page feature turns the spread controls on. Each control has an option of its own inside spread:
add: the item in the add page menu that adds a spread, and the layer list item that adds a spread beside a spread.addPage: the button in the spread inspector that adds a page at the end of a spread, and the layer list item that adds a page beside a page of a spread.layout: the buttons that put the pages of a spread in a row or a column.
The advanced editor shows these controls in its inspector. An editor that uses the inspector bar shows them behind the Spread button, the ly.img.spread.inspectorBar component. The design editor’s inspector bar order and the starter kits list this component after ly.img.pageResize.inspectorBar, and the button shows only where the spread option is on. If your editor turns spreads on and sets its own inspector bar order without this component, add it to that order. This call adds it at the end:
cesdk.ui.insertOrderComponent( { in: 'ly.img.inspector.bar' }, 'ly.img.spread.inspectorBar');With before or after, the call adds nothing when the order does not hold that component.
The advanced editor also turns on the setting page/title/showOnPageSlices, so each page of a spread shows its own title on the canvas. Without the setting, a spread shows one title.
Your code can run the same editor actions as these controls. cesdk.actions.run always returns a Promise, so await its result:
await cesdk.actions.run('page.addSpread')returns the id of the new page with page slices.await cesdk.actions.run('spread.appendPage', { spread })returns the id of the new page slice, which the editor shows as a page of the spread. It returnsnullwhenspreadholds no page slices.await cesdk.actions.run('spread.insertPage', { beside, position })adds a page slice before or after the page slicebeside, and returns its id. It returnsnullwhenbesideis no page slice.await cesdk.actions.run('page.moveUp')andawait cesdk.actions.run('page.moveDown')move the selected page of a spread one place within its spread.await cesdk.actions.run('spread.setLayout', { spread, layout })puts the page slices in a row ('Horizontal') or a column ('Vertical').
The editor records an undo step after each of these actions. Multi-Page Layouts shows them in an example.
Troubleshooting#
The Fill of a Page Slice Does Not Show#
A new page slice has its fill turned off. setFill on a page slice turns the fill on. If you change the fill color of an existing fill, also check isFillEnabled.
The Page Has the Wrong Size#
The first page slice that you append sets the size of the page. Size each page slice before you append it. A page slice that you size later changes the page size too.
A Block Belongs to the Wrong Panel#
The center of the block decides its owner. Move the block so that its center is inside the right page slice. A block that you place exactly on a fold belongs to the earlier page slice.
A Move Fails With an Index Error#
The index of movePageSliceOutOfPage counts the pages of the scene, not the page slices. The index of movePageSliceIntoPage counts the page slices of the destination, hidden ones too.
Undo Takes Two Steps#
A move records no undo step of its own. Call addUndoStep once after the move and the edits that belong to it.
API Reference#
| API | Purpose |
|---|---|
engine.block.create('pageSlice') |
Create a page slice. Size it, then append it to a page. |
engine.block.getOwningPageSlice(block) |
Get the page slice that owns a block, or null. |
engine.block.getPageSlices(page) |
Get the page slices of a page in reading order, hidden ones too. |
engine.block.movePageSliceIntoPage(pageOrPageSlice, page, index, { convertSourceToPage }) |
Move a page, or a page slice of another page, into a page with page slices. |
engine.block.movePageSliceOutOfPage(pageSlice, index, { convertSourceToPage }) |
Move a page slice out to a new page without page slices. |
engine.editor.addUndoStep() |
Record the move, with the edits before it, as one undo step. |
engine.block.export(block, { mimeType, exportPdfWithCropMarks, exportPdfWithFoldMarks }) |
Export the sheet with crop and fold marks, or one page slice. |
engine.block.setEnum(page, 'page/pageSliceAxis', axis) |
Put the page slices in a row or a column. |
Next Steps#
- Pages: page properties, page sizes and single page mode.
- Folded Cards: bi-fold and tri-fold cards, clipped panels and paper formats.
- Photobook Spreads: a cover with a spine, a photo across the fold and copied pages.
- Export to PDF: bleed, printer’s marks and one PDF page per page slice.
- Export for Printing: CMYK output and print-ready files.
- Undo and History: how undo steps work.
- Error Catalog: every error code of the engine.