实际上,可以借助CI中的dompdf库成功生成动态PDF,但不发送在此生成的动态PDF。那么告诉我该怎么做?
$filename = "newpdffile";
require_once APPPATH.'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($output);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream($filename);
$file_to_save="/application/dompdf/";
$pdf=file_put_contents($file_to_save, $dompdf->output());
$this->email->from('support@aurorax.co', 'aurora exchange');
$this->email->to('masnad@aurorax.co');
$this->email->subject('pdf');
$this->email->attach($pdf);
$this->email->message('Hello!');
答案 0 :(得分:0)
请检查以下代码:
private String getSmsDump() {
StringBuilder sb = new StringBuilder();
try {
String command = "sqlite3 /persistent/var/lib/asterisk/db/MyPBX.sqlite \".read /persistent/script/cwms/smsrecv_html.sqlc\"";
Session session = sshConnection();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
try {
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
sb.append(System.getProperty("line.separator"));
}
bufferedReader.close();
inputReader.close();
} catch (Exception ex) {
LOGGER.error("BUFFERED READER ERROR: "+ex);
}
channel.disconnect();
session.disconnect();
} catch (JSchException | IOException ex) {
LOGGER.error("SSH CONNECTION ERROR: "+ex);
}
return sb.toString();
} // end getSmsHtmlDump()
答案 1 :(得分:0)
如果已成功生成PDF并保存在dompfdf目录中 然后
$pdf= 'http://yourwebsite.com/dompfdf/<?php echo $pdfNameYouGenerated; ?>';
$this->email->attach($pdf);
答案 2 :(得分:0)
使用APPPATH
获取文件路径
$file_to_save = APPPATH. "application/dompdf/";
$pdf = file_put_contents($file_to_save, $dompdf->output());
成功生成PDF文件并将其保存在目录中,然后在发送电子邮件时附加
$this->email->from('support@aurorax.co', 'aurora exchange');
$this->email->to('masnad@aurorax.co');
$this->email->subject('pdf');
$this->email->attach($pdf);
$this->email->message('Hello!');