Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thai text not recognized properly in docxTemplater, causing improper line breaks #768

Open
iamfugui opened this issue Dec 27, 2024 · 2 comments

Comments

@iamfugui
Copy link

**Description:**
I am currently using docxTemplater to replace tags and generate a Thai language DOCX document. However, the generated text is not recognized as Thai; instead, it treats the entire string as a single character. As a result, the document does not break lines according to Thai word boundaries.

For example, the Thai sentence:
"เป็นสินค้าที่ทำรายได้ให้แก่ประเทศไทยมากที่สุดอย่างหนึ่ง" consists of 10 Thai words, but docxTemplater generates it as one unbreakable word.

Is there a way to resolve this issue?

Here is my code for reference:

const renderDoc = (renderDocData) => {
  loadFile("/doc/template.docx", (error, content) => {
    if (error) {
      console.error("An error occurred", error);
      throw error;
    }
    const zip = new PizZip(content);
    const doc = new Docxtemplater(zip, { paragraphLoop: true, linebreaks: true });

    // Fill data
    doc.render(renderDocData);

    const out = doc.getZip().generate({
      type: "blob",
      mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    });

    // Output document via Data-URI
    saveAs(out, formData.value.paperName + '.docx');
  });
};

Thank you for your assistance!

@edi9999
Copy link
Member

edi9999 commented Dec 27, 2024

Hello @iamfugui ,

Could you please send the document as generated by docxtemplater, and then a correct document with the same content ?

@edi9999
Copy link
Member

edi9999 commented Dec 27, 2024

I think this could be fixed if you can mark the language of the paragraph as "Thai" in your template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants