0

I have a html page with a form, where the end user generates a pdf of the form by pressing a specific button. My code:

<button onclick="generatePDF()">PDF</button>
        <script>
            function generatePDF() 
            {
                const element = document.getElementById('container');/Container is where the form is located

                var filecommessa = document.getElementById("commessajava").value;
                var filedata = document.getElementById("datajava").value;
                var filerapporto = "Rapporto_";
                var fileunderscore = "_";
                var fileName = filerapporto+filecommessa+fileunderscore+filedata;
                console.log(fileName);

                var opt = {
                filename: fileName,
                jsPDF: { unit: 'in', format: 'A3', orientation: 'landscape' }
                };
                html2pdf()
                .from(element)
                .set(opt)
                .save();
                

            }
        </script>

I have another function, which allows the user to send an email to a customer.

<script>
            function sendMail() 
            {
                var mailcommessa = document.getElementById("commessajava").value;
                var maildata = document.getElementById("datajava").value;
                var mailrapporto = "Rapporto ";
                var space = " ";
                var mailsubject = mailrapporto+mailcommessa+space+maildata;

                var link = "mailto:"
                + "?cc="
                + "&subject=" + encodeURIComponent(mailsubject)
                + "&body=" + encodeURIComponent(document.getElementById('myText').value)
                ;
    
                window.location.href = link;
            }
        </script>

I would to know how can I attach the generated pdf to the email automatically, instead of downloading it and then attaching the downloaded file to the email. If this is not possible with the mailto function, other similar suggestions will be appreciated. Thanks for your help.

I tried adding this line of code

                + "&attachments=" + "test.pdf"

in the mail to function, but I have no idea how to do it.

0 Answers0