Overview

Builder.App is the docbuilder.exe executable file which can be run from your application with the .docbuilder script file as a parameter to it.

If you are going to use ONLYOFFICE Document Builder with an application written in any programming language, run Document Builder executable from your application and use the .docbuilder script file for the document to be created as a parameter to it. It is much more flexible and allows to change the document script files (especially if there are more than one of them) independently of your application in future. You will only need to recompile your application if you need to add more document script files to it.

To launch ONLYOFFICE Document Builder executable file run the following command:

docbuilder.exe mydocument.docbuilder

Here docbuilder is the name of ONLYOFFICE Document Builder executive file. It must be used together with the path if the command is run from the folder different from the one where the executive is placed. The command will look like docbuilder.exe for Windows version and documentbuilder for Linux. The mydocument.docbuilder parameter is the name of the script file that will form the document contents (use it with the path if needed).

Visit the .docbuilder file section for more information about the file structure and rules used when creating it.

See the examples in some of the most popular programming languages at this page.

Known issues

If you use ONLYOFFICE Document Builder as both an application and a script, then you need to know some rules and limitations:

  1. To run ONLYOFFICE Document Builder executable in the C++ application, use the CDocBuilder.Run method in the following way:

    CDocBuilder::Initialize(sWorkDirectory.c_str());
    CDocBuilder oBuilder;
    oBuilder.Run("path-to-script.docbuilder");
    CDocBuilder::Dispose();
    

    Another way to do this is to use the docbuilder.exe executable file and run it with the .docbuilder file as an argument, where all the code for the document file creation will be written:

    docbuilder.exe "path-to-script.docbuilder"
    
  2. To set an argument to the builder class which can be trasferred to the program outside the CDocBuilder.ExecuteCommand method, add it as an additional property when running ONLYOFFICE Document Builder executable file or as a part of program JavaScript code, but not included into the document file script:

    Sets the --argument property to CDocBuilder.Run

    docbuilder.exe "--argument={\"company\":\"ONLYOFFICE\",\"product\":\"ONLYOFFICE Document Builder\"}" "path-to-script.docbuilder"
    

    Sets the --argument property using JavaScript code

    const sCompany = Argument["company"]
    const sProduct = Argument["product"]
    
  3. The builder object methods cannot be called with the JS variables. Wrap them with the jsValue instruction if necessary:

    const jsVar = "123.docx"
    builder.SaveFile("docx", jsVar) // Incorrect
    builder.SaveFile("docx", jsValue(jsVar)) // Correct
    
  4. For convenience, format types are replaced with strings.

    For example,

    builder.CreateFile("docx")
    

    is the same as

    CDocBuilder.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX)
    

    And

    builder.SaveFile("docx", file_path)
    

    is the same as

    CDocBuilder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, file_path)
    

    Format types

    StringFormat type
    "docx"OFFICESTUDIO_FILE_DOCUMENT_DOCX
    "doc"OFFICESTUDIO_FILE_DOCUMENT_DOC
    "odt"OFFICESTUDIO_FILE_DOCUMENT_ODT
    "rtf"OFFICESTUDIO_FILE_DOCUMENT_RTF
    "txt"OFFICESTUDIO_FILE_DOCUMENT_TXT
    "dotx"OFFICESTUDIO_FILE_DOCUMENT_DOTX
    "ott"OFFICESTUDIO_FILE_DOCUMENT_OTT
    "html"OFFICESTUDIO_FILE_DOCUMENT_HTML
    "pdf"OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF
    "pptx"OFFICESTUDIO_FILE_PRESENTATION_PPTX
    "ppt"OFFICESTUDIO_FILE_PRESENTATION_PPT
    "odp"OFFICESTUDIO_FILE_PRESENTATION_ODP
    "ppsx"OFFICESTUDIO_FILE_PRESENTATION_PPSX
    "potx"OFFICESTUDIO_FILE_PRESENTATION_POTX
    "otp"OFFICESTUDIO_FILE_PRESENTATION_OTP
    "xlsx"OFFICESTUDIO_FILE_SPREADSHEET_XLSX
    "xls"OFFICESTUDIO_FILE_SPREADSHEET_XLS
    "ods"OFFICESTUDIO_FILE_SPREADSHEET_ODS
    "csv"OFFICESTUDIO_FILE_SPREADSHEET_CSV
    "xltx"OFFICESTUDIO_FILE_SPREADSHEET_XLTX
    "ots"OFFICESTUDIO_FILE_SPREADSHEET_OTS
    "pdf"OFFICESTUDIO_FILE_CROSSPLATFORM_PDF
    "djvu"OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU
    "xps"OFFICESTUDIO_FILE_CROSSPLATFORM_XPS
    "pdfa"OFFICESTUDIO_FILE_CROSSPLATFORM_PDFA
    "jpg"OFFICESTUDIO_FILE_IMAGE_JPG
    "png"OFFICESTUDIO_FILE_IMAGE_PNG
    "bmp"OFFICESTUDIO_FILE_IMAGE_BMP
  5. The entire JavaScript context is a wrapper for its native CDocBuilder builderJS object. You need to work with it as with an ordinary JavaScript object. In this case, the jsValue instruction is not needed for the JS variables:

    builderJS.OpenFile("path_or_url", "x2t_additons_as_xml")
    builderJS.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX)
    // or builderJS.CreateFile("docx")
    builderJS.SetTmpFolder("folder")
    builderJS.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, "path", "x2t_additons_as_xml")
    // or builderJS.SaveFile("docx", "path", "x2t_additons_as_xml")
    builderJS.CloseFile()
    
  6. The Document Builder always works with one file. But there are cases when you need to be able to open another file not for adding its data to the content, but for some kind of manipulation (document comparison, mailmerge, etc). For such cases, the Document Builder provides the OpenTmpFile method:

    const tmpFile = builderJS.OpenTmpFile("path_or_url")
    

    Methods

    NameDescription
    IsValidSpecifies if the temporary file is valid (true).
    GetBinaryReturns Uint8Array with the doct/pptt/xlst binary content.
    GetFolderReturns the string path to the temporary folder with the temporary file contents.
    CloseCloses the file (removes the temporary folder contents).
    GetImageMapReturns a dictionary object with the imageId -> imagePath key-value pairs (for inserting into the document).
  7. To make the code shorter, use the following type definitions:

    typedef CDocBuilderValue CValue;
    typedef CDocBuilderContext CContext;
    typedef CDocBuilderContextScope CContextScope;
    

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).