Nutrient Web SDK
    Preparing search index...

    Function populateDocumentTemplate

    • This is used to Populate the document template (Docx format) with corresponding data.

      Returns a https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise|Promise resolving to an ArrayBuffer of a Docx, or rejecting with a NutrientViewer.Error.

      The resulting ArrayBuffer can be converted to PDF with (). and finally loaded with ().

      It requires a configuration object and config object with data TemplateDataToPopulateDocument which contains the data to be populated in document and delimiter marker to know placeholder of the data. If the configuration is invalid, the promise will be rejected with a NutrientViewer.Error.

      Parameters

      Returns Promise<ArrayBuffer>

      Promise that resolves to an ArrayBuffer of a file converted to PDF

      NutrientViewer.populateDocumentTemplate( { document: '/sales-report.docx', licenseKey: 'YOUR_LICENSE_KEY', }, { config: { delimiter: { start: '{{', end: '}}', }, }, model: { products: [ { title: 'Duk', name: 'DukSoftware', reference: 'DS0', }, { title: 'Tingerloo', name: 'Tingerlee', reference: 'T00', }, ], }, }, ) .then(arrayBuffer => { console.log('Successfully populated the template Document with data', arrayBuffer) }) .catch(error => { console.error(error.message) }) The delimiter object sets the pair of delimiters that encloses a template marker i.e. placeholder marker that need to be substituted with the data.

      The model object associates a template marker with the corresponding substitution in the final, produced document.

      === Supported Template Features === Placeholders let users substitute a marker with some text and Loops generate repetitions of a given pattern.

      The syntax for loops is # for the opening tag, and / for the closing one in the docs.

      For instance if the document contains:

      {#ITEMS} {name} {price} {/ITEMS}
      

      Here, ITEMS is the name of the loop template marker, and name and price are regular placeholder template markers over which the SDK iterates replacing the name placeholder with corresponding name value in model, and similarly the price placeholder is replaced by the corresponding price value in model.

      {
      model: {
      items: [
      {
      name: "A",
      price: 10
      },
      {
      name: "B",
      price: 15
      }
      ]
      }
      }