1

{#form}{importantFacts}{/form}

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});
    doc.setData(data);
    doc.render()
    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}\n\n`
    i++;
  }
  return outputString;
}
Phil
  • 435
  • 2
  • 9
  • 28
  • 1
    `.trim()` ? I can't offer more. Not familiar with that template syntax. – GetSet Jan 20 '21 at 06:31
  • no the orignal string is fine ... the template generates spacing for some reason.. thanks for helping tho – Phil Jan 20 '21 at 07:16
  • 1
    I see. Interesting. And is there a way to format a var? I have the github open and am looking – GetSet Jan 20 '21 at 07:21
  • 1
    In the "interactive demo" there appears to be a "data" object returned on the loaded docx? Can you change the properties using javascript? Can you "trim" the white-spaces before rendering, that is? That is how I would do it if I knew how. .... Referring to this demo https://docxtemplater.com/demo/#simple – GetSet Jan 20 '21 at 07:22
  • 1
    In a sense, could it be that the text justification is "justified". "Justified" will space words like that so it's like "newspaper print". Could this be a text/paragraph formatting issue? ... The *clue* for that is that more spacing, shrinks the spacing. (anyway upvoted you in hopes of more attention to this problem) – GetSet Jan 20 '21 at 07:35
  • 1
    You might want to show more of your code to rule out / rule in the other possibilities. – GetSet Jan 20 '21 at 07:42
  • @GetSet I apologize for the late response , Updated the question :) – Phil Jan 20 '21 at 08:02
  • 1
    Your "edit" only shows `formatArrayLines` once. So where is that being called? That was on question tho in comments. – GetSet Jan 20 '21 at 08:35
  • @GetSet it is being called just before sending the data to generate doc file .. input to that function is a simple string array .. but that as we can see gets converted to many white spaces in the .docx file – Phil Jan 20 '21 at 08:45
  • 1
    I don't know @Phill is it being converted to "whitespaces"? Seems like adding *more* spaces don't result in less spaces. Sounds like a formatting issue on styles of docx. Just saying. But you know, you being selfish with the code and all, what do i know – GetSet Jan 20 '21 at 12:59
  • 1
    I upvoted you tho. Text looks "justified". A styling issue. You can test it yourself. Open any wordprocessor or "publishing" app: type 3 relatively short words and set the paragraph to "justified". Text gets aligned so right edge is "neat" too. Thats what "justified" means. – GetSet Jan 20 '21 at 13:17
  • @GetSet you were right setting text align to left fixed this thank you so much !! – Phil Jan 21 '21 at 04:22
  • 1
    Glad it worked out @Phil. If you can post your solution to your own question, I will upvote it. I am curious on how that code looks for the text align. But in any event, glad you got that part of the code resolved. – GetSet Jan 21 '21 at 04:24
  • `{#form}{importantFacts}{/form}` i just selected this and selcted text align `left` it was previously set to `justified` which was the source of the problem :) – Phil Jan 21 '21 at 04:36
  • 1
    Ok, I get that part @Phil. But I meant post your source code so this question can help someone else later down the line. You *can* answer your own questions here, I think. And I can upvote. You can "accept". In this way, your solution will help future readers. No one really likes to dive in thru comments – GetSet Jan 21 '21 at 04:42
  • @GetSet done... – Phil Jan 21 '21 at 04:54

1 Answers1

1

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

{#form}{importantFacts}{/form}

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

Phil
  • 435
  • 2
  • 9
  • 28