### Customize DocumentBuilder Installation Path Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/configuration.md Use `make install` with `DEST_DIR` to specify a custom installation location for DocumentBuilder. This is useful for non-standard deployment scenarios. ```bash # Custom installation location make install DEST_DIR=/opt/custom/docbuilder ``` ```bash # Portable edition make install PACKAGE_EDITION=portable DEST_DIR=/opt/docbuilder-portable ``` ```bash # Custom version make install PRODUCT_VERSION=9.4.0 ``` -------------------------------- ### Section Interface Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/INDEX.md Methods for configuring page setup and layout for document sections. ```APIDOC ## Section Interface ### `Section.SetPageSize(w, h)` #### Description Set the width and height of the section's pages. #### Parameters - **w** (number) - Required - Page width. - **h** (number) - Required - Page height. ### `Section.SetPageMargins(l, t, r, b)` #### Description Set the page margins for the section. #### Parameters - **l** (number) - Required - Left margin. - **t** (number) - Required - Top margin. - **r** (number) - Required - Right margin. - **b** (number) - Required - Bottom margin. ### `Section.SetHeaderDistance(dist)` #### Description Set the distance from the top of the page to the header. #### Parameters - **dist** (number) - Required - The distance value. ### `Section.SetFooterDistance(dist)` #### Description Set the distance from the bottom of the page to the footer. #### Parameters - **dist** (number) - Required - The distance value. ### `Section.SetType(type)` #### Description Set the type of section (e.g., 'nextPage', 'continuous'). #### Parameters - **type** (string) - Required - The section type. ### `Section.SetEqualColumns(count, space)` #### Description Configure the section to have an equal number of columns with specified spacing. #### Parameters - **count** (number) - Required - The number of columns. - **space** (number) - Optional - The space between columns. ### `Section.GetHeader()` #### Description Get the header object for the section. ### `Section.GetFooter()` #### Description Get the footer object for the section. ``` -------------------------------- ### Reference Documents - Quick Reference Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Quick lookup guide with common patterns and code examples. ```APIDOC ## Quick Reference ### Description A concise guide for quick lookups, featuring common usage patterns and code examples. ``` -------------------------------- ### Create and Save a Presentation Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Use this snippet to create a new .pptx file, get the first slide, and save the presentation. ```javascript builder.CreateFile("pptx"); var oPresentation = Api.GetPresentation(); var oSlide = oPresentation.GetSlideByIndex(0); // Add content to slide builder.SaveFile("pptx", "./output.pptx"); builder.CloseFile(); ``` -------------------------------- ### API Reference - Section Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Section interface for page setup, margins, headers, and footers. ```APIDOC ## Section API ### Description Manages page setup, margins, headers, and footers for document sections. ### Settings - Page Setup - Margins - Headers - Footers ``` -------------------------------- ### Generate and Save an Invoice Document Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md This example demonstrates how to create a new document, add a title with formatting, include invoice details, create and populate a table with items, and finally save the document. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); // Title oParagraph.AddText("INVOICE"); oParagraph.SetJc("center"); var oRun = oParagraph.GetParagraph(0); oRun.SetBold(true); oRun.SetFontSize(24); // Invoice details oParagraph = oDocument.GetElement(1); oParagraph.AddText("Invoice #: INV-001\nDate: " + new Date().toLocaleDateString()); // Items table var oTable = Api.CreateTable(4, 3); oTable.SetWidth("auto"); // Headers var headers = ["Item", "Quantity", "Price"]; for (var i = 0; i < 3; i++) { var oCell = oTable.GetCell(0, i); var oContent = oCell.GetContent().GetElement(0); oContent.AddText(headers[i]); oContent.SetBold(true); } // Items var items = [ ["Widget A", "10", "$9.99"], ["Widget B", "5", "$19.99"], ["Service", "1", "$99.99"] ]; for (var row = 0; row < items.length; row++) { for (var col = 0; col < items[row].length; col++) { var oCell = oTable.GetCell(row + 1, col); oCell.GetContent().GetElement(0).AddText(items[row][col]); } } // Add table to document var tableParagraph = oDocument.GetElement(2); tableParagraph.AddTable(oTable); builder.SaveFile("docx", "./invoice.docx"); builder.CloseFile(); ``` -------------------------------- ### Create and Save Presentation Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/presentation.md Demonstrates how to create a new presentation, set its slide size, manage slides (get, create, add), and save the presentation. Uses the 16:9 widescreen preset for slide dimensions. ```javascript builder.CreateFile("pptx"); var oPresentation = Api.GetPresentation(); oPresentation.SetSizes(9144000, 6858000); // 16:9 widescreen // Get or create the first slide var oSlide = oPresentation.GetSlideByIndex(0); if (!oSlide) { oSlide = Api.CreateSlide(); oPresentation.AddSlide(oSlide); } // Add content to the slide (depends on Slide API) // var oShape = Api.CreateShape("rect", 1000000, 500000); // oSlide.AddShape(oShape); // Add more slides var oSlide2 = Api.CreateSlide(); oPresentation.AddSlide(oSlide2); builder.SaveFile("pptx", "./presentation.pptx"); builder.CloseFile(); ``` -------------------------------- ### API Patterns: Getting Sub-Objects Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Explains how to access child objects or elements from a parent object. ```javascript var oChild = oParent.GetChild(); ``` -------------------------------- ### Save Document in Different Formats Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/builder.md The `builder.SaveFile` method allows converting and saving the current document to various formats. This example shows converting a DOCX to PDF and saving a new spreadsheet as CSV. ```javascript // Convert a Word document to PDF builder.OpenFile("./document.docx", ""); builder.SaveFile("pdf", "./document.pdf"); builder.CloseFile(); // Create and save a spreadsheet as CSV builder.CreateFile("xlsx"); var oSheet = Api.GetActiveSheet(); builder.SaveFile("csv", "./output.csv"); builder.CloseFile(); ``` -------------------------------- ### Get Style by Name Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves an existing style from the document by its name. Check if the style exists before attempting to apply or modify it. ```javascript var oDocument = Api.GetDocument(); var oNoSpacingStyle = oDocument.GetStyle("No Spacing"); if (oNoSpacingStyle) { // Apply or modify the style } ``` -------------------------------- ### Get Default Paragraph Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves the default paragraph properties for the document. Use this to set line spacing and spacing after paragraphs. ```javascript var oDocument = Api.GetDocument(); var oParaPr = oDocument.GetDefaultParaPr(); oParaPr.SetSpacingLine(276, "auto"); oParaPr.SetSpacingAfter(200); ``` -------------------------------- ### Section Interface Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/types.md Represents a section of a document, allowing control over page setup. Use this to define page size, margins, header/footer distances, and column layouts. ```javascript interface Section { SetPageSize(width: number, height: number): void SetPageMargins(left: number, top: number, right: number, bottom: number): void SetHeaderDistance(distance: number): void SetFooterDistance(distance: number): void SetType(type: string): void SetEqualColumns(columnCount: number, spacing: number): void GetHeader(): Header GetFooter(): Footer } ``` -------------------------------- ### Get or Create Styles Safely Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/errors.md Implement a function to retrieve an existing style by name or create a new one if it doesn't exist. This prevents errors when applying styles. ```javascript function getOrCreateStyle(styleName) { var oStyle = oDocument.GetStyle(styleName); if (!oStyle) { oStyle = oDocument.CreateStyle(styleName, "paragraph"); } return oStyle; } ``` -------------------------------- ### Get Default Text Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves the default text properties for the document. Use this to set global font size, language, and font family. ```javascript var oDocument = Api.GetDocument(); var oTextPr = oDocument.GetDefaultTextPr(); oTextPr.SetFontSize(22); oTextPr.SetLanguage("en-US"); oTextPr.SetFontFamily("Calibri"); ``` -------------------------------- ### Create and Populate Spreadsheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Demonstrates creating a new spreadsheet, setting sheet name, adjusting column widths, adding headers and data, and saving the file. Ensure the builder object is initialized before use. ```javascript builder.CreateFile("xlsx"); var oSheet = Api.GetActiveSheet(); oSheet.SetName("Sales Report"); // Set column widths oSheet.SetColumnWidth(0, 15); // Column A oSheet.SetColumnWidth(1, 12); // Column B oSheet.SetColumnWidth(2, 20); // Column C // Add headers var oRange = oSheet.GetRange("A1"); oRange.SetValue("Product"); oRange.SetFontSize(12); oRange = oSheet.GetRange("B1"); oRange.SetValue("Quantity"); oRange = oSheet.GetRange("C1"); oRange.SetValue("Price"); // Add data oSheet.GetRange("A2").SetValue("Widget"); oSheet.GetRange("B2").SetValue(100); oSheet.GetRange("C2").SetValue(9.99); builder.SaveFile("xlsx", "./sales_report.xlsx"); builder.CloseFile(); ``` -------------------------------- ### Presentation Creation and Sizing Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/presentation.md Demonstrates how to create a new presentation, set its dimensions using presets or custom values, and manage slides. ```APIDOC ## CreateFile ### Description Creates a new presentation file. ### Method `builder.CreateFile(fileType)` ### Parameters - **fileType** (string) - Required - The type of file to create (e.g., "pptx"). ## GetPresentation ### Description Gets the current presentation object. ### Method `Api.GetPresentation()` ### Returns - **oPresentation** (Presentation) - The presentation object. ## SetSizes ### Description Sets the dimensions of the presentation slides. ### Method `oPresentation.SetSizes(width, height)` ### Parameters - **width** (number) - Required - The width of the slides in EMUs. - **height** (number) - Required - The height of the slides in EMUs. ## CreateSlide ### Description Creates a new blank slide. ### Method `Api.CreateSlide()` ### Returns - **oSlide** (Slide) - The newly created slide object. ## AddSlide ### Description Adds a slide to the presentation. ### Method `oPresentation.AddSlide(slide)` ### Parameters - **slide** (Slide) - Required - The slide object to add. ## GetSlideByIndex ### Description Retrieves a slide from the presentation by its index. ### Method `oPresentation.GetSlideByIndex(index)` ### Parameters - **index** (number) - Required - The zero-based index of the slide to retrieve. ### Returns - **oSlide** (Slide) - The slide object if found, otherwise null. ## SaveFile ### Description Saves the current presentation to a file. ### Method `builder.SaveFile(fileType, fileName)` ### Parameters - **fileType** (string) - Required - The type of file to save (e.g., "pptx"). - **fileName** (string) - Required - The name of the file to save. ## CloseFile ### Description Closes the current presentation file. ### Method `builder.CloseFile()` ``` -------------------------------- ### Get Number of Columns in Sheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Use this method to retrieve the total number of columns present in the active sheet. No specific setup is required beyond having an active sheet. ```javascript var oSheet = Api.GetActiveSheet(); var colCount = oSheet.GetColumns(); ``` -------------------------------- ### Basic Document Operations with builder Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Demonstrates fundamental file operations using the global 'builder' object, including creating, opening, saving, and closing documents. ```javascript builder.CreateFile("docx"); builder.OpenFile("./file.docx", ""); builder.SaveFile("docx", "./output.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Active Presentation Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/api-document.md Returns the active presentation object. Does not throw if a presentation is open. ```javascript builder.CreateFile("pptx"); var oPresentation = Api.GetPresentation(); var oSlide = oPresentation.GetSlideByIndex(0); builder.SaveFile("pptx", "./presentation.pptx"); builder.CloseFile(); ``` -------------------------------- ### Create and Populate a 3x3 Table Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/table.md Demonstrates creating a 3x3 table, setting its width to auto, and populating it with header and data rows. The table is then added to the document. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); // Create a 3x3 table var oTable = Api.CreateTable(3, 3); oTable.SetWidth("auto"); // Fill the table with data var headers = ["Name", "Age", "City"]; for (var i = 0; i < 3; i++) { var oCell = oTable.GetCell(0, i); oCell.GetContent().GetElement(0).AddText(headers[i]); } var data = [ ["Alice", "30", "New York"], ["Bob", "25", "Los Angeles"], ]; for (var row = 0; row < data.length; row++) { for (var col = 0; col < data[row].length; col++) { var oCell = oTable.GetCell(row + 1, col); oCell.GetContent().GetElement(0).AddText(data[row][col]); } } var oParagraph = oDocument.GetElement(0); oParagraph.AddTable(oTable); builder.SaveFile("docx", "./table_document.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Sheet Name Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Retrieves the current name of the sheet. This operation does not throw any errors. ```javascript var oSheet = Api.GetActiveSheet(); var sheetName = oSheet.GetName(); ``` -------------------------------- ### Get Table Column Count Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/table.md Returns the total number of columns present in the table. ```javascript var oTable = Api.CreateTable(3, 3); var colCount = oTable.GetColumnCount(); // Returns 3 ``` -------------------------------- ### Get Table Row Count Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/table.md Returns the total number of rows present in the table. ```javascript var oTable = Api.CreateTable(3, 3); var rowCount = oTable.GetRowCount(); // Returns 3 ``` -------------------------------- ### Create and Populate Table Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Use this snippet to create a table with a specified number of rows and columns, add a header row, and populate data rows. The table is then inserted into the document. ```javascript var oDocument = Api.GetDocument(); var oTable = Api.CreateTable(3, 3); oTable.SetWidth("auto"); // Add header row for (var i = 0; i < 3; i++) { var oCell = oTable.GetCell(0, i); oCell.GetContent().GetElement(0).AddText("Header " + (i + 1)); } // Add data rows var data = [["Cell 1", "Cell 2", "Cell 3"], ["Cell 4", "Cell 5", "Cell 6"]]; for (var row = 0; row < data.length; row++) { for (var col = 0; col < data[row].length; col++) { var oCell = oTable.GetCell(row + 1, col); oCell.GetContent().GetElement(0).AddText(data[row][col]); } } // Insert table into document var oParagraph = oDocument.GetElement(0); oParagraph.AddTable(oTable); ``` -------------------------------- ### Create and Apply Custom Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/style.md Demonstrates creating a custom paragraph style with specific spacing, font, and color properties, then applying it to a paragraph in the document. This ensures consistent formatting across document elements. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); // Create a custom heading style var oCustomHeading = oDocument.CreateStyle("CustomHeading", "paragraph"); var oParaPr = oCustomHeading.GetParaPr(); oParaPr.SetSpacingBefore(240); oParaPr.SetSpacingAfter(120); var oTextPr = oCustomHeading.GetTextPr(); oTextPr.SetFontSize(28); oTextPr.SetFontFamily("Arial"); oTextPr.SetBold(true); oTextPr.SetColor(0x2E, 0x74, 0xB5, false); // Apply the style to a paragraph var oParagraph = oDocument.GetElement(0); oParagraph.SetStyle(oCustomHeading); oParagraph.AddText("Custom Heading"); builder.SaveFile("docx", "./styled_document.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Row Count Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Returns the current number of rows in the sheet. This method does not throw errors. ```javascript var oSheet = Api.GetActiveSheet(); var rowCount = oSheet.GetRows(); ``` -------------------------------- ### Get Current Slide Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/presentation.md Retrieves the currently active slide in the presentation. Assumes a slide exists. ```javascript var oPresentation = Api.GetPresentation(); var oSlide = oPresentation.GetCurrentSlide(); ``` -------------------------------- ### Create a Simple Document Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Use this snippet to quickly generate a new DOCX document with basic text content. Ensure the DocumentBuilder is initialized before calling these methods. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); oDocument.GetElement(0).AddText("Hello, World!"); builder.SaveFile("docx", "./hello.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Active Spreadsheet Sheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/api-document.md Returns the active sheet in a spreadsheet document. Does not throw if a spreadsheet is open. ```javascript builder.CreateFile("xlsx"); var oSheet = Api.GetActiveSheet(); oSheet.SetName("Data"); builder.SaveFile("xlsx", "./spreadsheet.xlsx"); builder.CloseFile(); ``` -------------------------------- ### Accessing Document Objects with Api Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Shows how to interact with the document and create basic objects like colors and tables using the global 'Api' object. ```javascript var oDocument = Api.GetDocument(); var oColor = Api.CreateRGBColor(255, 0, 0); var oTable = Api.CreateTable(3, 3); ``` -------------------------------- ### Get Text Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/run.md Retrieves the TextProperties object for a given text run, allowing further formatting modifications. ```javascript var oRun = oParagraph.AddText("Formatted text"); var oTextPr = oRun.GetTextPr(); // TextProperties methods can be called on oTextPr ``` -------------------------------- ### Create and Apply RGB Color to Text and Fill Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Demonstrates creating an RGB color and applying it to text color and solid fill. Also shows applying a solid fill to a range of cells. ```javascript var oColor = Api.CreateRGBColor(255, 128, 0); // Orange var oRun = oParagraph.AddText("Colored text"); oRun.SetColor(255, 128, 0); var oFill = Api.CreateSolidFill(oColor); oRun.SetFill(oFill); var oRange = oSheet.GetRange("A1:C1"); oRange.SetFill(oFill); ``` -------------------------------- ### SetType Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/section.md Sets the section type, which determines how content flows between sections, such as starting on a new page or continuing. ```APIDOC ## SetType ### Description Sets the section type or break behavior. ### Method `Section.SetType(type: string): void` ### Parameters #### Path Parameters - **type** (string) - Required - Section type: `"continuous"`, `"nextPage"`, `"nextColumn"`, `"oddPage"`, `"evenPage"` ### Request Example ```javascript var oSection = oDocument.GetFinalSection(); oSection.SetType("continuous"); // No break before this section ``` ### Response #### Success Response (void) No return value. #### Error Response — Errors may occur for invalid type values. ``` -------------------------------- ### Style Templates and Formatting Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/MANIFEST.txt Explains the usage of style templates and document formatting options. ```APIDOC ## Style Templates and Formatting ### Description Explains the usage of style templates and document formatting options. ### Endpoint `/api/reference/style.md` ``` -------------------------------- ### Get Footer Object Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/section.md Retrieves the Footer object for the current section, enabling programmatic addition of footer content. ```javascript var oSection = oDocument.GetFinalSection(); var oFooter = oSection.GetFooter(); // Add footer content ``` -------------------------------- ### Get Style Name Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/style.md Retrieves the current name of a style. This is useful for identifying or referencing styles within the document. ```javascript var oStyle = oDocument.GetStyle("Heading 1"); var styleName = oStyle.GetName(); // Returns "Heading 1" ``` -------------------------------- ### Configure DocumentBuilder via Environment Variables Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Set environment variables to configure temporary directory, thread count, and request timeouts for DocumentBuilder. ```bash export DOCUMENTBUILDER_TEMP=/tmp/docbuilder export DOCUMENTBUILDER_THREADS=8 export DOCUMENTBUILDER_TIMEOUT=300 ``` -------------------------------- ### Get Header Object Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/section.md Retrieves the Header object for the current section, allowing for programmatic addition of header content. ```javascript var oSection = oDocument.GetFinalSection(); var oHeader = oSection.GetHeader(); // Add header content ``` -------------------------------- ### Presentation and Slide Management Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/MANIFEST.txt Explains how to manage presentations and their individual slides. ```APIDOC ## Presentation and Slide Management ### Description Explains how to manage presentations and their individual slides. ### Endpoint `/api/reference/presentation.md` ``` -------------------------------- ### Create a Spreadsheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md This snippet demonstrates creating a new XLSX spreadsheet, setting a header in cell A1, a numerical value in A2, saving the file, and closing the document. ```javascript builder.CreateFile("xlsx"); var oSheet = Api.GetActiveSheet(); oSheet.GetRange("A1").SetValue("Header"); oSheet.GetRange("A2").SetValue(42); builder.SaveFile("xlsx", "./data.xlsx"); builder.CloseFile(); ``` -------------------------------- ### API Reference - Builder Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Main entry point for file operations including CreateFile, OpenFile, SaveFile, and CloseFile. ```APIDOC ## Builder API ### Description Provides the main entry point for file operations. ### Methods - **CreateFile**: Creates a new document file. - **OpenFile**: Opens an existing document file. - **SaveFile**: Saves the current document. - **CloseFile**: Closes the current document. ``` -------------------------------- ### Open and Modify an Existing Document Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/builder.md Use `builder.OpenFile` to load an existing document from a given path. After making modifications, save the changes using `builder.SaveFile` and close the document with `builder.CloseFile`. ```javascript // Open an existing Word document builder.OpenFile("./input.docx", ""); var Api = editor; var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Additional content"); builder.SaveFile("docx", "./output.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Slide Count and Iterate Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/presentation.md Obtains the total number of slides and provides a loop structure to access each slide by its index. ```javascript var oPresentation = Api.GetPresentation(); var slideCount = oPresentation.GetSlideCount(); for (var i = 0; i < slideCount; i++) { var oSlide = oPresentation.GetSlideByIndex(i); // Process each slide } ``` -------------------------------- ### Create a New Word Document Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/builder.md Use `builder.CreateFile` to initialize a new document of the specified format. Access the created document using `Api.GetDocument()` and modify it as needed. Remember to save and close the file afterwards. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Hello, World!"); builder.SaveFile("docx", "./output.docx"); builder.CloseFile(); ``` -------------------------------- ### Get Final Document Section Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves the final section of the document. Use this to modify page size and margins for the entire document. ```javascript var oDocument = Api.GetDocument(); var oFinalSection = oDocument.GetFinalSection(); oFinalSection.SetPageSize(12240, 15840); oFinalSection.SetPageMargins(1440, 1440, 1440, 1440); ``` -------------------------------- ### Reference Documents - Configuration Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Environment variables, configuration files (DoctRenderer.config), and build options. ```APIDOC ## Configuration Reference ### Description Information on environment variables, configuration files (DoctRenderer.config), and available build options. ``` -------------------------------- ### Get Paragraph Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/paragraph.md Retrieves the paragraph properties object to modify paragraph formatting. This allows for further adjustments like line spacing. ```javascript var oParagraph = oDocument.GetElement(0); var oParaPr = oParagraph.GetParaPr(); oParaPr.SetSpacingLine(240, "auto"); ``` -------------------------------- ### CreateFile Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/INDEX.md Creates a new document file. ```APIDOC ## CreateFile ### Description Creates a new document file. ### Method CreateFile ### Class builder ### Document [builder.md](api-reference/builder.md) ``` -------------------------------- ### Get Document Elements Count Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Returns the total number of top-level elements (paragraphs, tables, etc.) in the document. This is useful for iterating through all elements. ```javascript var oDocument = Api.GetDocument(); var count = oDocument.GetElementsCount(); for (var i = 0; i < count; i++) { var oElement = oDocument.GetElement(i); // Process element } ``` -------------------------------- ### Convert Document Format Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md This snippet demonstrates converting a .docx file to .pdf and an .xlsx file to .csv. Ensure the input files exist before running. ```javascript // Convert DOCX to PDF builder.OpenFile("./document.docx", ""); builder.SaveFile("pdf", "./document.pdf"); builder.CloseFile(); // Convert XLSX to CSV builder.OpenFile("./data.xlsx", ""); builder.SaveFile("csv", "./data.csv"); builder.CloseFile(); ``` -------------------------------- ### Get Cell Value Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/range.md Retrieves the value of a specific cell. Returns the cell's content or null if the cell is empty. Does not throw exceptions. ```javascript var oRange = oSheet.GetRange("A1"); var cellValue = oRange.GetValue(); ``` -------------------------------- ### Get Cell Range Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Retrieves a specific cell or a group of cells using A1 notation. Invalid range references will result in errors. ```javascript var oSheet = Api.GetActiveSheet(); var oRange = oSheet.GetRange("C1"); oRange.SetFontSize(56); ``` -------------------------------- ### API Reference - Run Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Run interface for inline text formatting (bold, italic, color, font, etc.). ```APIDOC ## Run API ### Description Interface for applying inline text formatting. ### Formatting Options - Bold - Italic - Color - Font ``` -------------------------------- ### Create and Save a Spreadsheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Use this snippet to create a new .xlsx file, name a sheet, set a value in cell A1, and save it. ```javascript builder.CreateFile("xlsx"); var oSheet = Api.GetActiveSheet(); oSheet.SetName("Data"); var oRange = oSheet.GetRange("A1"); oRange.SetValue("Header"); builder.SaveFile("xlsx", "./output.xlsx"); builder.CloseFile(); ``` -------------------------------- ### Run Interface Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/types.md Represents a sequence of text with consistent formatting, enabling text manipulation, and formatting options like bold, italic, font size, and color. ```APIDOC ## Run ### Description Represents a continuous sequence of text with the same formatting. ### Methods - `AddText(text: string): Run` - `AddLineBreak(): Run` - `SetBold(bold: boolean): void` - `SetItalic(italic: boolean): void` - `SetUnderline(underline: boolean): void` - `SetFontSize(size: number): void` - `SetFontFamily(fontFamily: string): void` - `SetColor(red: number, green: number, blue: number): void` - `SetFill(fill: SolidFill | BlipFill): void` - `SetLanguage(languageCode: string): void` - `GetTextPr(): TextProperties` ### Properties - `text` (string): Text content - `size` (number): Font size in points - `fontFamily` (string): Font name - `red, green, blue` (number): RGB color values (0-255) - `fill` (SolidFill | BlipFill): Background fill - `languageCode` (string): Language code (e.g., "en-US") ``` -------------------------------- ### Merge Table Cells Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/table.md Combines a range of cells into a single cell, defined by start and end row/column indices. Returns the newly merged cell. ```javascript var oTable = Api.CreateTable(3, 3); var oMergedCell = oTable.MergeCells(0, 0, 0, 2); // Merge first 3 cells of first row oMergedCell.GetContent().GetElement(0).AddText("Merged Header"); ``` -------------------------------- ### Run Interface Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/types.md Represents a sequence of text with consistent formatting. Use this to manipulate text properties such as bold, italic, font size, and color. ```javascript interface Run { AddText(text: string): Run AddLineBreak(): Run SetBold(bold: boolean): void SetItalic(italic: boolean): void SetUnderline(underline: boolean): void SetFontSize(size: number): void SetFontFamily(fontFamily: string): void SetColor(red: number, green: number, blue: number): void SetFill(fill: SolidFill | BlipFill): void SetLanguage(languageCode: string): void GetTextPr(): TextProperties } ``` -------------------------------- ### Range Interface Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/types.md Represents a single cell or a range of cells within a spreadsheet sheet. Offers methods to set and get cell values, formatting, and borders. ```APIDOC ## Range Interface ### Description Represents a cell or range of cells. Allows setting and getting cell values, font properties, colors, alignment, number formats, and borders. ### Methods - `SetValue(value: string | number | boolean)`: Sets the value of the cell or range. - `GetValue()`: Returns the value of the cell or range. - `SetFontSize(size: number)`: Sets the font size in points. - `SetFontFamily(fontFamily: string)`: Sets the font family (name). - `SetBold(bold: boolean)`: Sets the bold property of the font. - `SetItalic(italic: boolean)`: Sets the italic property of the font. - `SetUnderline(underline: boolean)`: Sets the underline property of the font. - `SetColor(red: number, green: number, blue: number)`: Sets the font color using RGB values (0-255). - `SetFill(fill: SolidFill)`: Sets the background fill color of the cell or range. - `SetAlignment(horizontal: string, vertical: string)`: Sets the horizontal and vertical alignment. - `SetNumberFormat(format: string)`: Sets the number format (e.g., "0.00", "yyyy-mm-dd"). - `SetBorders(top: Border, bottom: Border, left: Border, right: Border, inside: Border)`: Sets the borders for the cell or range. - `Merge()`: Merges the cells in the range. ### Properties - `value` (string | number | boolean): Cell value. - `size` (number): Font size in points. - `fontFamily` (string): Font name. - `red, green, blue` (number): RGB color values (0-255). - `fill` (SolidFill): Background fill. - `horizontal` (string): Horizontal alignment ("left", "center", "right", "justify"). - `vertical` (string): Vertical alignment ("top", "center", "bottom"). - `format` (string): Excel-style format code. ``` -------------------------------- ### OpenFile Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/INDEX.md Opens an existing document file. ```APIDOC ## OpenFile ### Description Opens an existing document file. ### Method OpenFile ### Class builder ### Document [builder.md](api-reference/builder.md) ``` -------------------------------- ### Get Document Element by Index Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves a specific element from the document using its zero-based index. Use this to access and modify paragraphs, tables, or other document components. ```javascript var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Modified first paragraph"); ``` -------------------------------- ### API Patterns: Creating Objects Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Illustrates the common pattern for creating new objects within the DocumentBuilder API. ```javascript var oObject = Api.CreateXXX(param1, param2); ``` -------------------------------- ### Get Paragraph Properties for a Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/style.md Retrieves the ParagraphProperties object associated with a style. This object can then be modified to change paragraph formatting like spacing and line breaks. ```javascript var oHeadingStyle = oDocument.GetStyle("Heading 1"); var oParaPr = oHeadingStyle.GetParaPr(); oParaPr.SetSpacingAfter(240); oParaPr.SetKeepNext(true); ``` -------------------------------- ### Create Document Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/api-document.md Creates a new style in the document. Use for paragraph or character styling. Parameters must be valid. ```javascript builder.CreateFile("docx"); var oDocument = Api.GetDocument(); var oHeadingStyle = oDocument.CreateStyle("My Heading", "paragraph"); var oParaPr = oHeadingStyle.GetParaPr(); oParaPr.SetSpacingAfter(240); var oTextPr = oHeadingStyle.GetTextPr(); oTextPr.SetFontSize(28); oTextPr.SetBold(true); builder.SaveFile("docx", "./document.docx"); builder.CloseFile(); ``` -------------------------------- ### Basic Document Workflow Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md This snippet outlines the fundamental steps for creating, modifying, saving, and closing a document using the DocumentBuilder API. It shows how to create a new document or open an existing one, access its content, make changes, and then save and close the file. ```javascript // 1. Create or open a document builder.CreateFile("docx"); // New document // OR builder.OpenFile("./input.docx", ""); // Existing document // 2. Access the document var oDocument = Api.GetDocument(); // 3. Modify content var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Hello, World!"); // 4. Save the document builder.SaveFile("docx", "./output.docx"); // 5. Close the document builder.CloseFile(); ``` -------------------------------- ### Format Text Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md This snippet shows how to apply formatting to text, including making it bold, setting the font size, and changing the text color. This is typically done after adding text to a paragraph. ```javascript var oRun = oParagraph.AddText("Formatted text"); oRun.SetBold(true); oRun.SetFontSize(14); oRun.SetColor(255, 0, 0); ``` -------------------------------- ### Get Default Paragraph Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/document.md Retrieves the default paragraph style for the document. Modify properties like font size and family using the returned Style object. ```javascript var oDocument = Api.GetDocument(); var oNormalStyle = oDocument.GetDefaultStyle("paragraph"); var oTextPr = oNormalStyle.GetTextPr(); oTextPr.SetFontSize(12); oTextPr.SetFontFamily("Calibri"); ``` -------------------------------- ### Get Slide by Index Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/presentation.md Retrieves a specific slide using its zero-based index. Returns null if the slide does not exist. Consider creating or adding a slide if it's not found. ```javascript var oPresentation = Api.GetPresentation(); var oSlide = oPresentation.GetSlideByIndex(0); if (!oSlide) { // Slide doesn't exist, create it oSlide = Api.CreateSlide(); oPresentation.AddSlide(oSlide); } ``` -------------------------------- ### CreateFile Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/builder.md Creates a new document of the specified format. Use Api.GetDocument() to access the new document. ```APIDOC ## CreateFile ### Description Creates a new document of the specified type. ### Method `builder.CreateFile(format: string): void` ### Parameters #### Path Parameters - **format** (string) - Required - Document format: `"docx"` for text documents, `"xlsx"` for spreadsheets, `"pptx"` for presentations ### Returns `void` — No return value. Use `Api.GetDocument()`, `Api.GetActiveSheet()`, or `Api.GetPresentation()` to access the created document. ### Throws — This method does not throw; invalid formats may result in runtime errors. ### Example ```javascript // Create a new Word document builder.CreateFile("docx"); var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Hello, World!"); builder.SaveFile("docx", "./output.docx"); builder.CloseFile(); ``` ``` -------------------------------- ### Get a Specific Cell from a Table Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/table.md Retrieves a cell object using its row and column index. Ensure indices are within the table's bounds to avoid errors. ```javascript var oTable = Api.CreateTable(3, 3); var oCell = oTable.GetCell(0, 0); oCell.GetContent().GetElement(0).AddText("Header 1"); ``` -------------------------------- ### Handle Nonexistent Styles with CreateStyle Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/errors.md Retrieve a style using GetStyle and create it if it does not exist before applying it to a paragraph. ```javascript var oStyle = oDocument.GetStyle("NonexistentStyle"); if (!oStyle) { // Create the style if it doesn't exist oStyle = oDocument.CreateStyle("NonexistentStyle", "paragraph"); } var oParagraph = oDocument.GetElement(0); oParagraph.SetStyle(oStyle); ``` -------------------------------- ### API Patterns: Accessing Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Demonstrates the standard method for retrieving the value of a property from an object. ```javascript var value = oObject.GetProperty(); ``` -------------------------------- ### Get Used Range of Sheet Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/sheet.md Retrieves a Range object that covers all cells containing data within the active sheet. This is useful for operations that need to process all populated cells. ```javascript var oSheet = Api.GetActiveSheet(); var oUsedRange = oSheet.GetUsedRange(); ``` -------------------------------- ### Increase Worker Threads for DocumentBuilder Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/configuration.md Adjust the number of worker threads DocumentBuilder uses for processing. Increasing this can improve performance on multi-core systems. This example sets the threads to 8. ```bash export DOCUMENTBUILDER_THREADS=8 ./docbuilder script.docbuilder ``` -------------------------------- ### Handle File Not Found Errors Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/errors.md Implement a fallback mechanism to create a new document if the specified file cannot be opened. This ensures the application continues running. ```javascript var filePath = "./documents/report.docx"; try { builder.OpenFile(filePath, ""); // Process file } catch (e) { console.log("File not found, creating new document"); builder.CreateFile("docx"); // Create default content } ``` -------------------------------- ### Create DOCX Document and Get Document Object Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md This is valid DocumentBuilder code for creating a new DOCX file and obtaining a reference to the document object. Ensure the DocumentBuilder environment is set up before execution. ```javascript // This is valid DocumentBuilder code builder.CreateFile("docx"); var oDocument = Api.GetDocument(); ``` -------------------------------- ### API Patterns: Setting Properties Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Shows the consistent way to modify the properties of an object. ```javascript oObject.SetProperty(value); ``` -------------------------------- ### Get Text Properties for a Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/style.md Retrieves the TextProperties object for a style, allowing modification of text formatting such as font size, family, and color. Use this to define the appearance of text within a style. ```javascript var oHeadingStyle = oDocument.CreateStyle("Heading 1", "paragraph"); var oTextPr = oHeadingStyle.GetTextPr(); oTextPr.SetFontSize(40); oTextPr.SetFontFamily("Calibri Light"); oTextPr.SetColor(0x29, 0x33, 0x4F, false); ``` -------------------------------- ### Create Custom Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Creates and configures a custom paragraph style with specific spacing, alignment, font size, boldness, and color. ```javascript var oDocument = Api.GetDocument(); var oCustomStyle = oDocument.CreateStyle("CustomStyle", "paragraph"); // Configure paragraph properties var oParaPr = oCustomStyle.GetParaPr(); oParaPr.SetSpacingAfter(240); oParaPr.SetJc("center"); // Configure text properties var oTextPr = oCustomStyle.GetTextPr(); oTextPr.SetFontSize(16); oTextPr.SetBold(true); oTextPr.SetColor(0, 0, 128); // Navy blue ``` -------------------------------- ### Text Run Formatting Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/MANIFEST.txt Details how to format text runs, including inline styles and character-level formatting. ```APIDOC ## Text Run Formatting ### Description Details how to format text runs, including inline styles and character-level formatting. ### Endpoint `/api/reference/run.md` ``` -------------------------------- ### Section and Page Layout Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/MANIFEST.txt Describes how to manage section properties and page layout settings. ```APIDOC ## Section and Page Layout ### Description Describes how to manage section properties and page layout settings. ### Endpoint `/api/reference/section.md` ``` -------------------------------- ### Set Temporary Directory for DocumentBuilder Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/configuration.md Configure the temporary directory for intermediate files used by DocumentBuilder. This is useful for managing disk space or specifying a faster storage location. Examples are provided for Linux/macOS and Windows. ```bash # Linux/macOS export DOCUMENTBUILDER_TEMP=/var/tmp/docbuilder ./docbuilder script.docbuilder ``` ```batch # Windows set DOCUMENTBUILDER_TEMP=C:\Temp\docbuilder docbuilder.exe script.docbuilder ``` -------------------------------- ### Handle File Operations with Try-Catch Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/errors.md Use a try-catch-finally block to gracefully handle errors during file creation, saving, and closing operations. This ensures resources are managed properly. ```javascript builder.CreateFile("docx"); try { var oDocument = Api.GetDocument(); // ... document operations ... builder.SaveFile("docx", "./output.docx"); } catch (error) { console.error("Error: " + error); } finally { builder.CloseFile(); } ``` -------------------------------- ### Handle FileNotFound Error in OpenFile Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/errors.md Catch exceptions when opening a non-existent file with OpenFile and create a new file instead. ```javascript try { builder.OpenFile("./nonexistent.docx", ""); } catch (e) { console.error("File not found: " + e); // Create new file instead builder.CreateFile("docx"); } ``` -------------------------------- ### Set Script Execution Timeout for DocumentBuilder Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/configuration.md Configure the maximum time in seconds that a script can run before being terminated. This is useful for preventing long-running scripts from consuming excessive resources. This example sets the timeout to 600 seconds. ```bash export DOCUMENTBUILDER_TIMEOUT=600 ./docbuilder long_running_script.docbuilder ``` -------------------------------- ### Set Text to Bold Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/run.md Applies bold formatting to the text within a run. Use `false` to revert to normal text weight. ```javascript var oRun = oParagraph.AddText("Bold text"); oRun.SetBold(true); ``` -------------------------------- ### API Reference - Style Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md Style interface for creating and managing formatting templates. ```APIDOC ## Style API ### Description Allows creation and management of formatting templates. ### Operations - **CreateStyle**: Creates a new style. - **ManageStyle**: Modifies an existing style. ``` -------------------------------- ### CreateTable Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/INDEX.md Creates a table object. ```APIDOC ## CreateTable ### Description Creates a table object. ### Method CreateTable ### Class Api ### Document [api-document.md](api-reference/api-document.md) ``` -------------------------------- ### Apply Image Fill to a Shape Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Shows how to create an image fill using a specified image path and apply it to a rectangular shape. ```javascript var oImageFill = Api.CreateBlipFill("path/to/image.png"); var oShape = Api.CreateShape("rect", 2000000, 1000000); oShape.SetFill(oImageFill); ``` -------------------------------- ### Open and Edit a Document Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Use this snippet to open an existing .docx file, add text to the first paragraph, and save the modified document. ```javascript builder.OpenFile("./input.docx", ""); var oDocument = Api.GetDocument(); var oParagraph = oDocument.GetElement(0); oParagraph.AddText("Additional content"); builder.SaveFile("docx", "./output.docx"); builder.CloseFile(); ``` -------------------------------- ### Run.SetUnderline Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/run.md Sets the underline formatting for the text within the run. This allows for making text appear underlined. ```APIDOC ## Run.SetUnderline ### Description Sets whether the text is underlined. ### Method ```javascript Run.SetUnderline(underline: boolean): void ``` ### Parameters #### Path Parameters - **underline** (boolean) - Required - `true` for underline, `false` for normal ### Returns `void` — No return value. ### Example ```javascript var oRun = oParagraph.AddText("Underlined text"); oRun.SetUnderline(true); ``` ``` -------------------------------- ### Run.SetBold Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/api-reference/run.md Sets the bold formatting for the text within the run. This allows for making text appear in bold. ```APIDOC ## Run.SetBold ### Description Sets whether the text is bold. ### Method ```javascript Run.SetBold(bold: boolean): void ``` ### Parameters #### Path Parameters - **bold** (boolean) - Required - `true` for bold, `false` for normal ### Returns `void` — No return value. ### Example ```javascript var oRun = oParagraph.AddText("Bold text"); oRun.SetBold(true); ``` ``` -------------------------------- ### Apply Styles Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/README.md This code applies a predefined style, 'Heading 1', to the first paragraph of a document. Ensure the style exists in the document's style definitions. ```javascript var oStyle = oDocument.GetStyle("Heading 1"); var oParagraph = oDocument.GetElement(0); oParagraph.SetStyle(oStyle); ``` -------------------------------- ### Set Page Layout Source: https://github.com/onlyoffice/documentbuilder/blob/master/_autodocs/quick-reference.md Configures page size, margins, column layout, and header/footer distances for the document's section. ```javascript var oDocument = Api.GetDocument(); var oSection = oDocument.GetFinalSection(); // Set page size (US Letter: 8.5" x 11") oSection.SetPageSize(12240, 15840); // Set margins (1 inch = 1440 twips) oSection.SetPageMargins(1440, 1440, 1440, 1440); // Create 2-column layout oSection.SetEqualColumns(2, 720); // Set header/footer distance oSection.SetHeaderDistance(720); oSection.SetFooterDistance(720); ```