Search Docs
Loading...
Skip to content

Photobook Spreads

Build a photobook from spreads: a cover with a spine, and inside spreads of two facing pages. Place a photo across the fold, copy pages between spreads, show one spread at a time, and export the book for print.

8 mins
estimated time
GitHub

We build a square photobook with a cover and three inside spreads. We place one photo across the fold of the first inside spread. We copy a page into the second spread and duplicate a page in the third. Then we export the cover and the inside pages, and show only the first inside spread. This guide covers:

  • How spreads make a photobook
  • Building a cover with a spine, and inside spreads
  • Placing a photo across the fold
  • Copying a page into another spread, and duplicating a page
  • Exporting the cover and the inside pages for a print shop
  • Showing one spread at a time in single page mode

How a Photobook Is Built#

A photobook is a cover and a stack of inside spreads. CE.SDK builds each spread as one page with page slices, and the folds lie between the page slices.

  • The cover holds three page slices in a row: the back cover, the spine and the front cover.
  • An inside spread usually holds two page slices: the left and the right page.
  • A spread can hold any number of page slices.
  • All page slices of a row share one height.
  • The content of a spread is a child of the page, in the coordinates of the whole spread. The origin is the top-left corner of the trim. The bleed starts at x = -3 mm and y = -3 mm.

Folded Products and Spreads explains the model, the size rules and the ownership rules of page slices.

Create the Scene#

Create a design scene with a vertical stack, so the spreads show one under the other in reading order. Set the design unit to millimeters, so all sizes in this guide are in millimeters.

let scene = try engine.scene.create(sceneLayout: .verticalStack)
try engine.scene.setDesignUnit(.mm)
let stack = try engine.block.find(byType: .stack)[0]

Create a Spread#

A spread is a page that holds one page slice per book page. To build one:

  1. Create a page and add it to the stack.
  2. Turn on its margin, which CE.SDK uses as the bleed, and set 3 mm on each side.
  3. Add one page slice per book page, each 210 mm high, with its own width and name.

The helper below puts these steps together:

private struct SpreadPage {
let name: String
let width: Float
}
@MainActor
private func createSpread(engine: Engine, stack: DesignBlockID, pages: [SpreadPage]) throws -> DesignBlockID {
let spread = try engine.block.create(.page)
try engine.block.appendChild(to: stack, child: spread)
// A 3 mm bleed on every side of the spread
try engine.block.setBool(spread, property: "page/marginEnabled", value: true)
for side in ["top", "bottom", "left", "right"] {
try engine.block.setFloat(spread, property: "page/margin/\(side)", value: 3)
}
for page in pages {
let pageSlice = try engine.block.create(.pageSlice)
// Size the page slice before it joins the spread.
try engine.block.setWidth(pageSlice, value: page.width)
try engine.block.setHeight(pageSlice, value: 210)
try engine.block.setName(pageSlice, name: page.name)
try engine.block.appendChild(to: spread, child: pageSlice)
}
return spread
}

The spread takes its size from its page slices, so we never size the page. The engine lays out the spread on its next update. Calls such as getOwningPageSlice, duplicate and export lay out the spread themselves.

Build the Cover Spread#

Two covers of 210 × 210 mm and a 12 mm spine make a cover sheet of 432 × 210 mm. The spine is a page slice like the covers. A clipped spine stops a title that is longer or wider than the spine at its folds.

To put a title on the spine:

  1. Create a text block of 120 × 8 mm as a child of the cover spread. Center its text in both directions.
  2. Turn it by 90 degrees with setRotation. The turn keeps the center of the block, but moves its position.
  3. Set the position after the turn. The position is then the top-right corner of the turned frame. So x is the right edge of the title, and y is its top edge.

For a 12 mm spine, x = 210 + 12 / 2 + 8 / 2 = 220 mm and y = (210 - 120) / 2 = 45 mm. If you set the position first, the turn moves the title off the spine. For a title that reads from bottom to top, turn it by -90 degrees. Then x is the left edge of the title and y is its bottom edge.

The print shop gives the spine width for a page count and a paper. Keep it in one value, such as spineWidth, and compute the title position from it. To change the spine of an existing cover:

  • Call setWidth on the spine page slice. The front cover and its content move by the change of the width.
  • A block on the spine does not move. Set the x of the title again to 210 + spineWidth / 2 + 4 mm.
  • The new sizes show after the next update.
// The print shop gives the spine width for a page count and a paper.
let spineWidth: Float = 12
let cover = try createSpread(engine: engine, stack: stack, pages: [
SpreadPage(name: "Back Cover", width: 210),
SpreadPage(name: "Spine", width: spineWidth),
SpreadPage(name: "Front Cover", width: 210),
])
let spine = try engine.block.getPageSlices(cover)[1]
// A title longer or wider than the spine stops at its folds.
try engine.block.setClipped(spine, clipped: true)
let spineTitle = try engine.block.create(.text)
try engine.block.appendChild(to: cover, child: spineTitle)
try engine.block.replaceText(spineTitle, text: "Summer 2026")
try engine.block.setTextFontSize(spineTitle, fontSize: 14)
let titleWidth: Float = 120
let titleHeight: Float = 8
try engine.block.setWidth(spineTitle, value: titleWidth)
try engine.block.setHeight(spineTitle, value: titleHeight)
try engine.block.setEnum(spineTitle, property: "text/horizontalAlignment", value: "Center")
try engine.block.setEnum(spineTitle, property: "text/verticalAlignment", value: "Center")
// setRotation keeps the center and moves the position. After the turn,
// the position is the top-right corner of the turned frame.
try engine.block.setRotation(spineTitle, radians: .pi / 2)
try engine.block.setPositionX(spineTitle, value: 210 + spineWidth / 2 + titleHeight / 2)
try engine.block.setPositionY(spineTitle, value: (210 - titleWidth) / 2)

Build the Inside Spreads#

An inside spread holds a left and a right page of 210 × 210 mm. We build the first inside spread with both pages. The second and the third start with their left page only. They get their right pages from a copy and a duplicate. We append the spreads after the cover, so the stack holds the book in reading order.

let firstSpread = try createSpread(engine: engine, stack: stack, pages: [
SpreadPage(name: "Lake Left", width: 210),
SpreadPage(name: "Lake Right", width: 210),
])
// The second spread gets its right page from a copy, the third from a
// duplicate.
let secondSpread = try createSpread(engine: engine, stack: stack, pages: [
SpreadPage(name: "Trip Left", width: 210),
])
let thirdSpread = try createSpread(engine: engine, stack: stack, pages: [
SpreadPage(name: "Notes Left", width: 210),
])
let lakePages = try engine.block.getPageSlices(firstSpread)
let lakeLeft = lakePages[0]
let lakeRight = lakePages[1]

Place a Photo Across the Fold#

A photo across the fold is one graphic block with an image fill. It covers both pages of the spread and the bleed. It is 426 × 216 mm and starts at x = -3 mm and y = -3 mm. Its center is on the fold.

  • The page slice under the center of the photo owns it. On the fold, the earlier page slice owns it, so getOwningPageSlice returns the left page.
  • A clipped page slice cuts the blocks that it owns at its folds and at the page edges with their bleed. The inside page slices stay unclipped, so the photo crosses the fold.
// One photo over both pages, bleed included, centered on the fold
let photo = try engine.block.create(.graphic)
try engine.block.setShape(photo, shape: engine.block.createShape(.rect))
let photoFill = try engine.block.createFill(.image)
try engine.block.setURL(
photoFill,
property: "fill/image/imageFileURI",
value: baseURL.appendingPathComponent("ly.img.image/images/sample_1.jpg"),
)
try engine.block.setFill(photo, fill: photoFill)
try engine.block.appendChild(to: firstSpread, child: photo)
try engine.block.setPositionX(photo, value: -3)
try engine.block.setPositionY(photo, value: -3)
try engine.block.setWidth(photo, value: 426)
try engine.block.setHeight(photo, value: 216)
// On the fold, the earlier page slice owns the photo.
let photoOwner = try engine.block.getOwningPageSlice(photo)
print("The photo belongs to the left page:", photoOwner == lakeLeft)

Copy a Page Into Another Spread#

We give the right page of the first inside spread a dark fill and a white caption. Then we copy that page into the second inside spread, as its right page. On the first spread, the photo hides the dark fill. The left page owns the photo, so the copy takes the fill and the caption, but not the photo.

To copy a page into another spread:

  1. Save the page slice with saveToString. The string holds its fill and the blocks that it owns on its page.
  2. Load the string back as a block. The loaded page slice keeps its content until it joins a spread.
  3. Insert the loaded page slice into the other spread with insertChild. The next update puts the content onto that spread, at the new place of the page slice.

insertChild runs no update itself. An inserted page slice takes the largest height of its row. So a taller copy makes the whole spread taller, and a shorter copy takes the height of the spread. Copy pages between spreads of one page size.

In code, saveToString(blocks:) saves the page slice and load(from:) loads it. Both are async:

// A page slice fill and the blocks that a page slice owns go with a copy.
let pageFill = try engine.block.createFill(.color)
try engine.block.setColor(pageFill, property: "fill/color/value", color: .rgba(r: 0.1, g: 0.2, b: 0.3, a: 1))
try engine.block.setFill(lakeRight, fill: pageFill)
let caption = try engine.block.create(.text)
try engine.block.appendChild(to: firstSpread, child: caption)
try engine.block.replaceText(caption, text: "At the lake")
try engine.block.setTextFontSize(caption, fontSize: 12)
try engine.block.setTextColor(caption, color: .rgba(r: 1, g: 1, b: 1, a: 1))
try engine.block.setWidth(caption, value: 190)
try engine.block.setHeight(caption, value: 10)
try engine.block.setPositionX(caption, value: 220)
try engine.block.setPositionY(caption, value: 180)
let saved = try await engine.block.saveToString(blocks: [lakeRight])
let copy = try await engine.block.load(from: saved)[0]
try engine.block.setName(copy, name: "Trip Right")
// The copy becomes the right page. The next update puts the caption on it.
try engine.block.insertChild(into: secondSpread, child: copy, at: 1)

Duplicate a Page With Its Content#

To make two facing pages with one layout, we build the left page and duplicate it. Here, we put a note on the left page of the third inside spread and duplicate that page.

let note = try engine.block.create(.text)
try engine.block.appendChild(to: thirdSpread, child: note)
try engine.block.replaceText(note, text: "Notes")
try engine.block.setTextFontSize(note, fontSize: 18)
try engine.block.setWidth(note, value: 190)
try engine.block.setHeight(note, value: 12)
try engine.block.setPositionX(note, value: 10)
try engine.block.setPositionY(note, value: 20)
// The duplicate goes right after the left page, with a copy of the note.
let leftPage = try engine.block.getPageSlices(thirdSpread)[0]
let rightPage = try engine.block.duplicate(leftPage)
try engine.block.setName(rightPage, name: "Notes Right")
print("Pages in the third spread:", try engine.block.getPageSlices(thirdSpread).count)

duplicate on a page slice puts the duplicate right after the original in the same spread. The duplicate takes a copy of each block that the original owns, at the same place on the duplicate.

  • The page slices after the duplicate move right by its width, with their content.
  • The spread grows by the width of the duplicate.
  • The new positions show after the next update.

Export the Photobook for Print#

Print shops usually ask for two files: the cover as one sheet, and the inside pages.

  • Export the cover page for the cover file. It gives one PDF page with a TrimBox of 432 × 210 mm. exportPdfWithCropMarks and exportPdfWithFoldMarks draw the cut and the two spine folds. printMarkOffset set to the bleed starts the marks at the edge of the bleed.
  • For the inside pages, hide the cover with setVisible and export the scene with exportPdfPageSlices turned on. A hidden page is left out of the export. The canvas does not show the cover until you make it visible again.
  • setIncludedInExport turned off on the cover does not do the same. It keeps three empty PDF pages for the cover.
  • Each page slice gives one PDF page, in reading order, with the bleed on all four sides. A page of 210 × 210 mm gives a PDF page of 216 × 216 mm. At the fold, the bleed shows the facing page.
  • Without exportPdfPageSlices, the export gives one PDF page per spread.
  • exportPdfWithHighCompatibility is on by default and rasterizes the photos at the export resolution. pdfImageQuality below 1 stores them as JPEG, which keeps the file much smaller.
  • Ask the print shop whether the first inside page is a left or a right page. To start with a right page, begin with a spread of one page slice.
  • Without a license, each export carries a watermark.

Export to PDF describes the TrimBox, the BleedBox and the printer’s marks. Export for Printing describes CMYK output.

// The cover as one sheet, with crop marks and the two spine folds
let coverPDF = try await engine.block.export(cover, mimeType: .pdf, options: ExportOptions(
exportPdfWithCropMarks: true,
exportPdfWithFoldMarks: true,
printMarkOffset: 3,
pdfImageQuality: 0.9,
))
// The inside pages: one PDF page per page slice, without the cover
// A hidden page is left out of a scene export.
try engine.block.setVisible(cover, visible: false)
let insidePDF: Data
do {
defer { try? engine.block.setVisible(cover, visible: true) }
insidePDF = try await engine.block.export(scene, mimeType: .pdf, options: ExportOptions(
exportPdfPageSlices: true,
pdfImageQuality: 0.9,
))
}
// Save the PDFs to files or share them in your app.
print("Cover PDF bytes:", coverPDF.count)
print("Inside PDF bytes:", insidePDF.count)

Each export returns the PDF as Data. Write it to a file in your app container, or upload it to the print shop.

Show One Spread at a Time#

Single page mode shows only the pages that you name. On a phone screen, it lets users edit one spread, or one page, at a time. The setting features/singlePageModeEnabled turns it on, and setCurrentPages also accepts page slices.

try engine.editor.setSettingBool("features/singlePageModeEnabled", value: true)
// Two page slices of one spread form a facing pair.
try engine.scene.setCurrentPages([lakeLeft, lakeRight])
print("Shown pages:", try engine.scene.getCurrentPages().count)
// The camera does not move by itself.
try await engine.scene.zoom(to: firstSpread, paddingLeft: 40, paddingTop: 40, paddingRight: 40, paddingBottom: 40)
  • One page slice shows only that page of its spread.
  • Two neighboring page slices of one spread show a facing pair. The engine does not check that they are neighbors.
  • getCurrentPages returns what single page mode shows, or an empty array while the setting is off.
  • The camera does not move to the shown pages. Call zoom(to:) on the spread as the last step.
  • The scene does not save the shown pages. Set them again after you load a scene.
  • An export of the scene holds every page, including the pages that single page mode hides.

Troubleshooting#

  • The photo across the fold is cut in half. The page slice that owns the photo is clipped. Turn its clip off.
  • The spine title is off center after a spine change. A block on the spine does not move with it. Set its position again.
  • A copied page shows no content. The copy has not joined a spread, or no update ran yet. Insert it into a spread and let the engine update.
  • Single page mode shows all spreads. The setting features/singlePageModeEnabled is off. Turn it on, then call setCurrentPages.
  • Single page mode shows an empty canvas. The camera points at another part of the scene. Call zoom(to:) on the shown spread.

API Reference#

API Purpose
engine.scene.create(sceneLayout: .verticalStack) Create a scene that shows the spreads in reading order.
engine.scene.setDesignUnit(.mm) Work in millimeters.
engine.block.create(.page) Create a spread.
engine.block.appendChild(to:child:) Add a spread to the stack, or a page slice to a spread.
engine.block.setBool(_:property:value:) Turn on the bleed of a spread with page/marginEnabled.
engine.block.setFloat(_:property:value:) Set the bleed on one side of a spread with page/margin/top and the other sides.
engine.block.create(.pageSlice) Create a page of a spread, or the spine.
engine.block.setWidth(_:value:) Size a page slice before it joins a spread, or change the spine width.
engine.block.getPageSlices(_:) Get the pages of a spread in reading order.
engine.block.setClipped(_:clipped:) Cut the blocks of a page slice at its folds and at the page edges with their bleed.
engine.block.setRotation(_:radians:) Turn the spine title.
engine.block.getOwningPageSlice(_:) Get the page slice that owns a block, or nil.
engine.block.duplicate(_:) Duplicate a page with its content in the same spread.
engine.block.saveToString(blocks:) Save a page slice with the blocks that it owns.
engine.block.load(from:) Load the saved page slice.
engine.block.insertChild(into:child:at:) Insert the loaded page slice into a spread.
engine.block.export(_:mimeType:options:) Export the cover as one sheet, or the scene as one PDF page per page slice.
ExportOptions(exportPdfWithCropMarks:exportPdfWithFoldMarks:printMarkOffset:pdfImageQuality:) Ask for the marks of the cover sheet.
ExportOptions(exportPdfPageSlices:pdfImageQuality:) Ask for one PDF page per page slice.
engine.block.setVisible(_:visible:) Leave the cover out of a scene export.
engine.editor.setSettingBool(_:value:) Turn on single page mode with features/singlePageModeEnabled.
engine.scene.setCurrentPages(_:) Show one page or a facing pair.
engine.scene.getCurrentPages() Get what single page mode shows.
engine.scene.zoom(to:paddingLeft:paddingTop:paddingRight:paddingBottom:) Bring the shown spread into view.

Next Steps#