将pdf邮件cakepdf附加到tcpdf

问题描述

您好社区,我不知道如何使用CakePHP 4中的cakepdf插件将tcpdf生成的pdf附加到邮件中,这是发送邮件的控制器的作用

public function register()
{
 $names = $doctor->name.' '.$doctor->last_name;
            $dir = new Folder(WWW_ROOT.'register'.DS.$doctor->code_cmp,TRUE,0775);
            //this function generates the pdf
            $this->generatepdf($names,$doctor->specialty,$dir->path);
            
            $email = new Mailer('blue-profile');
            $email->setEmailFormat('html')
                ->setViewVars([
                    'names' => $names,'specialty' => $doctor->specialty,'user' => $doctor->code_cmp,'password' => $this->request->getData('password')
                ])
                ->setFrom(['[email protected]' => 'Abbott'])
                ->setTo($doctor->email)
                ->setSubject('Bienvenido APLV Expertos Pediatras')
                ->viewbuilder()->setTemplate('welcome')->setLayout('default');
                if($email->send()){
                    $message['success'] = "success";
                    echo json_encode($message);
                    die();
                }
}

生成pdf的功能

public function generatepdf($names,$specialty,$dir)
{
    $this->set(compact('names','specialty','dir'));
    $this->viewbuilder()->setClassName('CakePdf.Pdf');
    $this->viewbuilder()->setoptions([
        'pdfConfig' => [
            'margin' => [
                'top' => 0,'bottom' => 0,'left' => 0,'right'=> 0
            ],'orientantion' => 'portrait','download' => false,]
    ]);        
    
}

这是我的pdf模板

require_once(ROOT.DS.'vendor'.DS.'tecnickcom'.DS.'tcpdf'.DS.'tcpdf.PHP');
require_once(ROOT.DS.'vendor'.DS.'tecnickcom'.DS.'tcpdf'.DS.'config'.DS.'tcpdf_config.PHP');
class PdfInvitation extends TCPDF{
public function Header() {
    $bMargin = $this->getBreakMargin();
    $auto_page_break = $this->AutopageBreak;
    $this->SetAutopageBreak(false,0);
    $this->SetAutopageBreak($auto_page_break,$bMargin);
    $this->setPageMark();
   }
}
 $img = WWW_ROOT.'img'.DS.'fond-pdf-notify.jpg';
 $pdf = new PdfInvitation('P',PDF_UNIT,PDF_PAGE_FORMAT,'UTF-8',FALSE);
 ////code pdf
 $pdf->AddPage();
 $pdf->lastPage();
 $file = $pdf->Output('Diplomas-Eval-SER.pdf','S');
 //I saw this code in the plugin documentation
 $CakePdf = new \CakePdf\Pdf\CakePdf();
 $CakePdf->template(DS.'Doctors'.DS.'pdf'.DS.'invitation','invitation');
 $CakePdf->write($dir.DS.$file);

也许我做错了事,感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)