Pages


insert a page break at the start of the document body.

    var body = ctx.document.body; 
    body.insertBreak(Word.BreakType.page, Word.InsertLocation.start);

Insert Breaks

$("#setup").click(() => tryCatch(setup)); 
$("#line").click(() => tryCatch(insertLineBreak));
$("#page").click(() => tryCatch(insertPageBreak));

async function insertLineBreak() {
  Word.run(async (context) => {
    context.document.body.paragraphs.getFirst().insertBreak(Word.BreakType.line, "After");

    await context.sync();
    console.log("success");
  });
}

async function insertPageBreak() {
  await Word.run(async (context) => {
    context.document.body.paragraphs.getFirst().insertBreak(Word.BreakType.page, "After");

    await context.sync();
    console.log("success");
  });
}

async function setup() {
  await Word.run(async (context) => {
    context.document.body.clear();
    context.document.body.insertParagraph(
      "Video provides a powerful way to help you prove your point.",
      "Start"
    );
    context.document.body.paragraphs
      .getLast()
      .insertText(
        "To make your document look professionally produced.",
        "Replace"
      );

    console.log("success");
  });
}

async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    console.error(error);
  }
}


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext