Skip to main content

insertPage

This function inserts a new page into the document at a specified location.

Prompts

  • Insert a page at the current location
  • Add a page at the end of the document
  • Add a page at the start of the document

Function registration

let func = new RegisteredFunction({
name: "insertPage",
description:
"Inserts a new page into the document at a specified location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description:
"Where to insert the new page ('current', 'start', or 'end')",
},
},
required: ["location"],
},
examples: [
{
prompt: "Insert a page at the current location",
arguments: { location: "current" },
},
{
prompt: "Add a page at the end of the document",
arguments: { location: "end" },
},
{
prompt: "Add a page at the start of the document",
arguments: { location: "start" },
},
],
});

Parameters

NameTypeExampleDescription
locationstring"current"Specifies where to insert a new page ("current", "start", or "end").

Function execution

(function () {
let func = new RegisteredFunction({
name: "insertPage",
description:
"Inserts a new page into the document at a specified location.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description:
"Where to insert the new page ('current', 'start', or 'end')",
},
},
required: ["location"],
},
examples: [
{
prompt: "Insert a page at the current location",
arguments: { location: "current" },
},
{
prompt: "Add a page at the end of the document",
arguments: { location: "end" },
},
{
prompt: "Add a page at the start of the document",
arguments: { location: "start" },
},
],
});

func.call = async function (params) {
Asc.scope.location = params.location;

await Asc.Editor.callCommand(function () {
let doc = Api.GetDocument();
if ("start" === Asc.scope.location) doc.MoveCursorToStart();
else if ("end" === Asc.scope.location) doc.MoveCursorToEnd();

Api.GetDocument().InsertBlankPage();
});
};
return func;
})();

Methods used: GetDocument, MoveCursorToStart, MoveCursorToEnd, InsertBlankPage, Asc.scope object

Result