I have a Vue.JS web app with client side only.
In that app I'm exporting a string as .docx file using Docx.JS.

What I want is redirecting my user to a 'New Email' window in his email,
with the .docx file attachment.

Basically if I could add a file attachment to the 'mailto:' it was perfect,
I know it can't be done so I need an alternative.

I only saw solutions to this question that either use a backend server, or
only send a link to the file in the mail, and not adding a file attachment.

Here is my code which exports the .docx file:

generateDocx() {

            const docx = new Docx.Document();
            const packer = new Docx.Packer();

            let paragraph = new Docx.Paragraph().left().bidirectional(); // Rtl switches right and left, so left stands for right

            let lines = this.transcription.split('\n');

            lines.forEach((line) => {
                paragraph.addRun(new Docx.TextRun(line)
                    .size(28) // Measured in half points


            packer.toBlob(docx).then(blob => {
                let now = new Date(Date.now());
                let formattedNow = now.getDate() + "-" + now.getMonth() + "-" + now.getFullYear() + " " + now.toLocaleTimeString('he-IL');
                saveAs(blob, "BizVoice Doc " + formattedNow + ".docx");

As you can see I have it as a blob at some point if it helps.
Thanks in advance!

0 Answers