duplicatePage
This API is a preview. Preview APIs are unstable and may change without warning. You can't release public apps using this API until it's stable.
Duplicates a page.
Usage
Duplicate a page by ID
import { duplicatePage, getCurrentPageMetadata } from "@canva/design";const currentPage = await getCurrentPageMetadata();if (currentPage.type !== 'absolute' || currentPage.id == null) {throw new Error('Current page does not have an ID');}const pageMetadata = await duplicatePage({sourcePageId: currentPage.id,mode: 'after_source',});
Insert the duplicated page after another page
import { addPage, duplicatePage, getCurrentPageMetadata } from "@canva/design";const currentPage = await getCurrentPageMetadata();if (currentPage.type !== 'absolute' || currentPage.id == null) {throw new Error('Current page does not have an ID');}const insertAfterPage = await addPage();if (insertAfterPage.type !== 'absolute' || insertAfterPage.id == null) {throw new Error('Inserted page does not have an ID');}const pageMetadata = await duplicatePage({sourcePageId: currentPage.id,targetPageId: insertAfterPage.id,mode: 'after_target',});
Insert the duplicated page at the start of the design
import { duplicatePage, getCurrentPageMetadata } from "@canva/design";const currentPage = await getCurrentPageMetadata();if (currentPage.type !== 'absolute' || currentPage.id == null) {throw new Error('Current page does not have an ID');}const pageMetadata = await duplicatePage({sourcePageId: currentPage.id,mode: 'before_first_page',});
Insert the duplicated page before the source page
import { duplicatePage, getCurrentPageMetadata } from "@canva/design";const currentPage = await getCurrentPageMetadata();if (currentPage.type !== 'absolute' || currentPage.id == null) {throw new Error('Current page does not have an ID');}const pageMetadata = await duplicatePage({sourcePageId: currentPage.id,mode: 'before_source',});
Insert the duplicated page at the end of the design
import { duplicatePage, getCurrentPageMetadata } from "@canva/design";const currentPage = await getCurrentPageMetadata();if (currentPage.type !== 'absolute' || currentPage.id == null) {throw new Error('Current page does not have an ID');}const pageMetadata = await duplicatePage({sourcePageId: currentPage.id,mode: 'after_last_page',});
Parameters
optsDuplicatePageOptionsOptions for duplicating the page.
Options for inserting a page adjacent to the source page.
modestringThe type of insertion.
Available values:
"before_source""after_source"
sourcePageIdPageIdThe ID of the page to duplicate.
Options for inserting a page at the start or end of the design.
modestringThe type of insertion.
Available values:
"before_first_page""after_last_page"
sourcePageIdPageIdThe ID of the page to duplicate.
Options for inserting a page adjacent to a target page.
modestringThe type of insertion.
Available values:
"before_target""after_target"
targetPageIdPageIdThe ID of the page to insert the new page adjacent to.
sourcePageIdPageIdThe ID of the page to duplicate.
Returns
The metadata of the duplicated page. This is a Promise that resolves with the following object:
Information about a page within a design with fixed or unbounded dimensions.
typestringThe type of page.
The only valid value is "absolute".
idPageIdStable identifier for this page within the design.
dimensionsPageDimensionsThe dimensions of the page, in pixels.
This may be undefined because some types of pages don't have dimensions, such as whiteboards.
widthnumberThe width of the page, in pixels.
heightnumberThe height of the page, in pixels.
titlestringThe name of the page.
This is optional and will be empty if the user hasn't set a title.
Pages that do not have fixed or unbounded dimensions currently do not return metadata.
typestringThe type of page.
The only valid value is "unsupported".