How can I create a plugin to delete the current page from a Word document?
Hey @ajay
So, basic information on macros and plugins:
https://api.onlyoffice.com/plugin/basic
Also in this section you can find working examples of plugins and macros.
https://api.onlyoffice.com/plugin/code
The structure of the text document is described here:
https://api.onlyoffice.com/docbuilder/textdocumentapi
What do you mean by ‘current page’ in the document editor?
Blank page or page with content?
I want to delete the page currently pointed to by my cursor, and I wish for both the page and its contents to be deleted.
Also, could you tell me how I can create a plugin to apply my custom style to a portion of a paragraph or text selected by the user?
Hi, @ajay
unfortunately, we don’t have the ability to use something like Page1.Delete().
Can you provide an analogue of the VBA script, if you have one?
@Nikolas
I don’t have a VBA script for this, but I am using the code below to add a new page in the document. If you manage to delete the current section’s contents and then remove the section break, I think it will work. i tried to do this but unable to found any method on section to delete contents or delete current section completly.
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oDocument.InsertContent([oParagraph]);
// oParagraph.AddPageBreak();
var oSection = oDocument.CreateSection(oParagraph);
oSection.SetType(“nextPage”);
oDocument.InsertContent([oSection]);
var oNextSection = oSection.GetNext();
var nWidth = 8.5 * 1440; // 12240 twips
var nHeight = 11 * 1440; // 15840 twips
var isPortrait = true;
oNextSection.SetPageSize(nWidth, nHeight, isPortrait);
var topMarginCm = 1.2;
var bottomMarginCm = 1.2;
var leftMarginCm = 1.5;
var rightMarginCm = 1.5;
var topMarginTwips = topMarginCm * 566.929134;
var bottomMarginTwips = bottomMarginCm * 566.929134;
var leftMarginTwips = leftMarginCm * 566.929134;
var rightMarginTwips = rightMarginCm * 566.929134;
oNextSection.SetPageMargins(leftMarginTwips, topMarginTwips, rightMarginTwips, bottomMarginTwips);
Hello @ajay
We are taking closer look at your scenario. I will update the thread once any news come up.