Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在电子邮件中附加使用HTML div创建的PDF(Java)_Javascript_Java_Html_Css_Jakarta Mail - Fatal编程技术网

Javascript 在电子邮件中附加使用HTML div创建的PDF(Java)

Javascript 在电子邮件中附加使用HTML div创建的PDF(Java),javascript,java,html,css,jakarta-mail,Javascript,Java,Html,Css,Jakarta Mail,我需要利用HTMLdiv标记的内容并从中创建PDF,同时维护与内容相关联的css 我在后端使用Java发送电子邮件,因此我希望能够完整地附加这个带有CSS的PDF,并将其与电子邮件一起发送 我真的需要一些帮助来帮助我如何做到这一点。>此示例代码将帮助您提出一个想法。 > This sample code will help you an dgive u an idea. <?php > /* > mPDF: Generate PDF from HT

我需要利用HTMLdiv标记的内容并从中创建PDF,同时维护与内容相关联的css

我在后端使用Java发送电子邮件,因此我希望能够完整地附加这个带有CSS的PDF,并将其与电子邮件一起发送

我真的需要一些帮助来帮助我如何做到这一点。

>此示例代码将帮助您提出一个想法。
> This sample code will help you an dgive u an idea.     <?php
>     /*
>     mPDF: Generate PDF from HTML/CSS (Complete Code)
>     */
>     require_once( 'mpdf/mpdf.php'); // Include mdpf
>     $stylesheet = file_get_contents('assets/css/pdf.css'); // Get css content
>     $html = '<div id="pdf-content">
>                   Your PDF Content goes here (Text/HTML)
>              </div>';
>     // Setup PDF
>     $mpdf = new mPDF('utf-8', 'A4-L'); // New PDF object with encoding & page size
>     $mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping
>     $mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping
>     // PDF header content
>     $mpdf->SetHTMLHeader('<div class="pdf-header">
>                               <img class="left" src="assets/img/pdf_header.png"/>                      
>                           </div>'); 
>     // PDF footer content                      
>     $mpdf->SetHTMLFooter('<div class="pdf-footer">
>                             <a href="http://www.lubus.in">www.lubus.in</a>
>                           </div>'); 
>      
>     $mpdf->WriteHTML($stylesheet,1); // Writing style to pdf
>     $mpdf->WriteHTML($html); // Writing html to pdf
>     // FOR EMAIL
>     $content = $mpdf->Output('', 'S'); // Saving pdf to attach to email 
>     $content = chunk_split(base64_encode($content));
>     // Email settings
>     $mailto = $email;
>     $from_name = 'LUBUS PDF Test';
>     $from_mail = 'email@domain.com';
>     $replyto = 'email@domain.com';
>     $uid = md5(uniqid(time())); 
>     $subject = 'mdpf email with PDF';
>     $message = 'Download the attached pdf';
>     $filename = 'lubus_mpdf_demo.pdf';
>     $header = "From: ".$from_name." <".$from_mail.">\r\n";
>     $header .= "Reply-To: ".$replyto."\r\n";
>     $header .= "MIME-Version: 1.0\r\n";
>     $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
>     $header .= "This is a multi-part message in MIME format.\r\n";
>     $header .= "--".$uid."\r\n";
>     $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
>     $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
>     $header .= $message."\r\n\r\n";
>     $header .= "--".$uid."\r\n";
>     $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
>     $header .= "Content-Transfer-Encoding: base64\r\n";
>     $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
>     $header .= $content."\r\n\r\n";
>     $header .= "--".$uid."--";
>     $is_sent = @mail($mailto, $subject, "", $header);
>     //$mpdf->Output(); // For sending Output to browser
>     $mpdf->Output('lubus_mdpf_demo.pdf','D'); // For Download
>     exit;
>     ?>

谢谢。用javascript创建pdf并将其传递给服务器端代码,还是在服务器端创建pdf然后与邮件一起附加?这两种方法都可以。无论以何种方式运行代码都是正确的。我会在服务器端创建一个pdf,然后用邮件附加一个pdf。如果这个答案有帮助,请投票。谢谢。你知道如何用java来实现吗?我确实读过关于iText的文章,但我不确定。而且我正在使用Bootstrap3作为css。我不知道这在服务器端将如何工作。使用PHP,我喜欢dompdf.ca和html2pdf.com。将html的字符串传递给他们,就可以得到pdf了。不确定css的Bootstrap3。