首页 > 其他分享 >laravel8 生成pdf

laravel8 生成pdf

时间:2024-02-02 17:05:25浏览次数:20  
标签:laravel8 work 生成 job exp pdf nt name

 private static function createPdfSendEmail($job_notes_id)
    {
        # 信息
        $recruit_job_notes_auth = DB::table('notes_auth')->select(["mobile", "job_id"])->find($job_notes_id);

        if (!$recruit_job_notes_auth->mobile) {
            return ["status" => Status::ERROR, "msg" => "投递信息有误"];
        }
        $recruit_job = DB::table('job')->select("city")->find($recruit_job_notes_auth->job_id);

        if (!$recruit_job->city) {
            return ["status" => Status::ERROR, "msg" => "所在城市信息有误"];
        }
        $field = [
            "id", "user_name", "head_img", "education", "work_st", "weChat", "email", "mobile",
            "birth", "work_date", "adv"
        ];
        $nt    = Note::where(
            [['mobile', "=", $recruit_job_notes_auth->mobile], ['status', "=", Status::REGULAR], ['is_deleted', '=', Status::NOT_DELETE]]
        )->select($field)->first();

        if (!$nt) {
            return ["status" => Status::ERROR, "msg" => "信息有误"];
        }
        $nt->work_exp;
        $nt->notes_intention;
        $nt->educational_back;

    
-------------------- 以上是你需要的数据 -----------------


        // 创建 TCPDF 实例
        $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8');

        // 设置文档信息
        $pdf->SetCreator('招聘');
        $pdf->SetAuthor('招聘');
        $pdf->SetTitle('招聘');
        $pdf->SetSubject('招聘');
        $pdf->SetKeywords('TCPDF, PDF, PHP');

        // 设置页眉和页脚信息
        //        $pdf->SetHeaderData('tcpdf_logo.jpg', 30, 'job.eeeknow.com/recruit/pc/', '学会偷懒,并懒出效率!', [0, 64, 255], [0, 64, 128]);
        //        $pdf->setFooterData([0, 64, 0], [0, 64, 128]);

        // 设置页眉和页脚字体
        $pdf->setHeaderFont(['stsongstdlight', '', '10']);
        $pdf->setFooterFont(['helvetica', '', '8']);

        // 设置默认等宽字体
        $pdf->SetDefaultMonospacedFont('courier');

        // 设置间距
        $pdf->SetMargins(15, 6, 15); //页面间隔
        $pdf->SetHeaderMargin(5);    //页眉top间隔
        $pdf->SetFooterMargin(10);   //页脚bottom间隔

        // 设置分页
        $pdf->SetAutoPageBreak(true, 10);

        // set default font subsetting mode
        $pdf->setFontSubsetting(true);

        //设置字体 stsongstdlight支持中文
        $pdf->SetFont('stsongstdlight', '', 10);

        $pdf->setPrintHeader(false);
        # 页尾
        //        $pdf->setPrintFooter(false);
        // 设置字体间距
        $pdf->SetFontSpacing(0.3);

        $b     = date('Y-m-d H:i:s', $nt->birth);
        $date1 = new \DateTime($b);
        $date2 = new \DateTime(date("y-m-d H:i:s"));

        $diff = $date1->diff($date2);

        $yearsDiff = ceil($diff->days / 365);
        $sex       = $nt->sex == 1 ? '男' : '女';

        $html = '<html><body>';
        $html .= '<div style="text-align:center;font-size: 22px;line-height: 1.5">' .
            $nt->user_name;
        $html .= '<div style=" font-size: 10px;">' . $sex .
            ' | 年龄:' .
            $yearsDiff . ' | ' . $nt->mobile . '</div>';

        $intention = '';
        foreach ($nt->notes_intention as $datum) {
            if ($datum->work_city == $recruit_job->city) {
                $city_name = DB::table('city')->select(["name"])->where("id", $datum->work_city)
                    ->first();
                $city_name = $city_name ? $city_name->name : '';

                $position_category      = DB::table('category')->select(["name"])->where("id", $datum->position_category_id)
                    ->first();
                $position_category_name = $position_category ? $position_category->name : '';

                $intention .= '<div style="font-size: 10px;line-height: 0.5;">' . $datum->work_year .
                    '年经验 | 意向:' .
                    $position_category_name . ' | ' . $nt->mobile . ' | 薪资:' . $datum->salary1 / 1000 . ' k -' .
                    $datum->salary2 / 1000 .
                    ' k |  城市:' . $city_name . '</div>';
            }
            continue;
        }


        $html .= $intention . '<div style="text-align: left;"><span style="font-size: 16px;">优势</span><hr>';
        $html .= '<div style="font-size: 12px;line-height: 1.5">' . $nt->adv . '</div>';
        $html .= '</div>';


        $expHl = '<div style="text-align: left;"><span style="font-size: 16px;">经验</span><hr>';
        foreach ($nt->work_exp as $k1 => $exp) {
            if ($exp->tp == 1) {
                $expHl .= '<div style="font-size: 12px;">';
                $expHl .= '<span>' . $exp->business_name . '         ' . $exp->position_name .
                    '               ' . date('Y.m.d', $exp->work_date_st) .
                    ' - ' . date('Y.m.d', $exp->work_date_ed) . '</span>';
                $expHl .= '<div>' . $exp->work_exp . '</div>';
                $expHl .= '</div>';
            }
        }
        $expHl .= '</div>';
        $html  .= $expHl;

        $expHl2 = '<div style="font-size: 16px;text-align: left;"><span>经历</span><hr>';
        foreach ($nt->work_exp as $expw) {
            if ($expw->tp == 2) {
                $expHl2 .= '<div style="font-size: 12px;">';
                $expHl2 .= '<span>' . $expw->business_name . '        ' . $expw->position_name .
                    '                 ' . date('Y.m.d', $expw->work_date_st) .
                    ' - ' . date('Y.m.d', $expw->work_date_ed) . '</span>';

                $expHl2 .= '<div>' . $expw->work_exp . '</div>';
                $expHl2 .= '</div>';
            }
        }
        $expHl2 .= '</div>';
        $html   .= $expHl2;


        $eduHl = '<div style="font-size: 16px;text-align: left;"><span>背景</span><hr>';
        foreach ($nt->educational_back as $edu) {
            $education = Status::EDUCATION[$edu->education];
            $dd        = $edu->university_name . '        ' . $education . '        ' . $edu->speciality;
            $eduHl     .= '<div style="font-size: 12px;">' . $dd . '</div>';
        }
        $eduHl .= '</div>';
        $html  .= $eduHl . '</div></body></html>';

        $pdf->AddPage();
        $pdf->writeHTML($html, true, false, true, false, '');

        $pdfName = rand(1000, 9999) . $nt->user_name;
        # 保存 PDF 到指定路径
        if (!is_dir(storage_path('file/save/pdf'))) {
            File::makeDirectory(storage_path('file/save/pdf'), 0777, true);
        }

        # PDF输出的方式。I,默认值,在浏览器中打开;D,点击下载按钮, PDF文件会被下载下来;F,文件会被保存在服务器中;S,PDF会以字符串形式输出;E:PDF以邮件的附件输出。
           // $path = storage_path('file/save/pdf/' . $pdfName . '.pdf');
           //  $pdf->Output($path, 'F'); 保存到指定目录
       
        $user = ['email' => '[email protected]'];
        self::sendPdfEmail($path, $user);    # 发送邮件
        return ["status" => Status::SUCCESS, "msg" => ""];
    }

 

邮箱接收pdf 预览结果:

 

标签:laravel8,work,生成,job,exp,pdf,nt,name
From: https://www.cnblogs.com/G921123/p/18003452

相关文章

  • JS直接下载PDF文件
    if(ext=="pdf"){varindex=_fileUri.lastIndexOf('/');varname=_fileUri.substr(index+1);varxhr=newXMLHttpRequest();xhr.open('get',_fileUri,true);xhr.responseType='b......
  • JWT的生成和校验
    JWT(JSONWebToken)是一种开放标准(RFC7519),用于在网络上安全传输信息的简洁、自包含的方式。它通常被用于身份验证和授权机制。JWT由三部分组成:头部(Header)、载荷(Payload)和签名(Signature)。1、头部(Header):包含了关于生成该JWT的信息以及所使用的算法类型。2、载荷(payload): ......
  • 新型生成式 AI 助手 Amazon Q(预览版)上线
    今天,我们宣布推出AmazonQ,这是一种新型的生成式人工智能助手,专门用于满足办公场景需要,可以根据客户业务进行定制。客户可以使用AmazonQ进行对话、解决问题、生成内容、获取见解并采取行动,所有这些都基于客户自身的信息存储库、代码、数据和企业系统。AmazonQ为员工提供即时......
  • 最小生成树
    概念 第1题   生成树任何一个无向连通图的最小生成树 1.有一棵或多棵   正确 2.只有一棵 错误 3.一定有多棵 错误 4.可能不存在 错误  第2题   生成树有几个以下叙述中,正确的是()1.只要无向连通图中没有权值相同的边,则其最小生成树......
  • 《计算机程序的构造和解释(原书第2版)》PDF
    内容简介《计算机程序的构造和解释》成型于美国麻省理工学院(MIT)多年使用的一本教材,1984年出版,1996年修订为第二版。在过去的二十多年里,该书对于计算机科学的教育计划产生了深刻的影响。在第二版中,大部分重要程序设计系统都重新修改并做过测试,包括各种解释器和编译器。作者根据其后......
  • UniGUI使用ADO组件、调用数据库的存储过程、生成EXECL表的例子
    UniGUI使用ADO组件、调用数据库的存储过程、生成EXECL表的例子(自己学习记录一下,不一定合理,仅供参考)本例子是使用ADO等组件连接一个云服务器的一个数据库,调用GetOrg存储过程,把机构信息展现把结果导出的一个EXECL表里,并下载把显示的HSate的值进行替换1表示正常,其他表示暂停......
  • 3. 统计学生成绩
    objecttest3{caseclassstudent(id:String,gender:String,score:Map[String,Int])//读取文件的方法:definputStudentList(filename:String):List[student]={//读取文件并按行进行切割varlines=scala.io.Source.fromFile(filename).getLine......
  • 文心一言APP上线新功能,一张照片、三句话即可生成专属数字分身
    只需一张照片、录制三句话,就能拥有一个自己的数字分身?这不是科幻电影,而是文心一言APP上线的新功能-数字分身。目前,文心一言APP正在内测数字分身新功能,明天起,iOS和Android用户升级新版本后,均可免费使用该功能,极速体验创建和使用数字分身的乐趣。据了解,文心一言APP新功能极大缩短了......
  • laravel生成二维码,并添加背景图片,图标logo
    1、安装组件composerrequiresimplesoftwareio/simple-qrcode1.3.*在 config/app.php 注册服务提供者:SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class同样在 config/app.php 添加 QrCode 门面:'QrCode'=>SimpleSoftwareIO\QrCode\Facades\QrCode::class2......
  • 后台生成单个Word文档
    在实际项目开发中经常会遇到一种场景,客户希望点击页面上的生成文件按钮,执行程序动态填充数据到Word模板,直接在后台生成Word文档,而无需显示Word文档。目前网上有一些针对此需求的方案,但每个方案都存在很多各自的问题。与其他方案对比采用Jacob生成Word文档方案动态生成的Word文......