locked
How to attach jspdf output to email RRS feed

  • Question

  • User1185448985 posted

    i want to know if i can attach jspdf output to email

    for now i am creating jsPDF file with an image of the current page using dom-to-image to capture the images along with text

    and i would like to open new mail window on the client side with the file attached where he/she can select a receiver and type the subject etc.. is it possible ?

    my cshtml page have a div that contains a table with images and texts, the div id = "pdfImg"

    script:

            function sendEmail() {
                domtoimage.toPng(document.getElementById('pdfImg'))
                    .then(function (blob) {
                        var pdf = new jsPDF('l', 'pt', [$('#pdfImg').width(), $('#pdfImg').height()]);
                        pdf.addImage(blob, 'PNG', 0, 0, $('#pdfImg').width(), $('#pdfImg').height());
                        pdf.save("story.pdf");
                    });

    the button that fires the function:

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"></script>
    
    <a href="javascript:pdf()" type="button" class="btn btn-outline-secondary btn-sm"><i class="fa fa-file-pdf-o"></i> PDF</a>
    

    thank you

    Monday, September 14, 2020 1:32 PM

Answers

  • User-821857111 posted

    i would like to open new mail window on the client side with the file attached where he/she can select a receiver and type the subject etc.. is it possible ?
    No. The only way to invoke a mail client using client-side code is to use the mailto protocol, and that doesn't support attachments. 

    You can use AJAX to post the PDF content to the server and then use .NET code to send it as part of an email.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 9, 2020 6:46 AM