How to remove spaces between a string in Docxtemplater?


The problem is that the string takes over the whole line

For example :

1. This is test

2. This is a longer string so spacing is generated less

However if i give longer strings it works fine , Basically the behaviour is that it covers the whole line.. how to remove these whitepspaces

Please let me know if more code needs to be shown.

Generating doc file

const tempFileName = `output-${new Date().getTime()}.docx`;
    const content = fs.readFileSync(path.resolve(__dirname, formPath), 'binary');
    const zip = new PizZip(content);
    const doc = new Docxtemplater(zip, {nullGetter: () => " ", linebreaks: true});
    const buf = doc.getZip().generate({type: 'nodebuffer'});
    fs.writeFileSync(path.resolve(__dirname, tempFileName), buf);

Function used to print array of strings

function formatArrayLines(lines: string[]) {
  let outputString = '';
  let i = 1;
  for (const line of lines) {
    outputString += `${i}. ${line}nn`
  return outputString;


So the solution to this problem is not related to the source code but the alignment in the document


So selecting this and setting text align left solved the problem.

Leave a Reply

Your email address will not be published. Required fields are marked *