通过电子邮件直接在按钮点击上将画布图像作为pdf文件发送

时间:2016-01-03 20:02:14

标签: php jquery html canvas html-email

通过使用下面的jquery代码,我可以将画布图像下载为pdf。

<script>
jQuery(document).ready(function () {

        html2canvas(jQuery("#abc"), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);

                // Convert and download as image 
                Canvas2Image.saveAsPNG(canvas); 
                jQuery("#img-out").append(canvas);
                // Clean up 
                //document.body.removeChild(canvas);
            }
        });

}); 

</script>


<script>
jQuery(document).ready(function () {
jQuery('#btnSave').click(function() {       
        html2canvas(jQuery("canvas"), {
            onrendered: function(canvas) {         
                var imgData = canvas.toDataURL(
                    'image/png');              
                var doc = new jsPDF('p', 'mm');
                doc.addImage(imgData, 'PNG', 37, 10);
                doc.save('test.pdf');
            }
        });
    });
    }); 
</script>

但我也想通过电子邮件直接发送这个生成的pdf文件,使用下面的PHP脚本。

<?php
 $to= 'test@gmail.com' . ',';
$to .= 'testamjadm61@gmail.com';
$sub='test1';
$msg= <<<EOF
   <html>
   <body>
   Pls find the atteached pdf file.
    </body>
    </html>
EOF;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: <centos_test@example.com>' . "\r\n";
?>

是否可以使用此脚本附加文件? 如果是这样,你能告诉我该怎么做吗? 如果不是,请告诉我另一种方法来做同样的事情。

请注意:我希望所有的php和jquery都在一个包含电子邮件功能的php文件中。

0 个答案:

没有答案
相关问题