`composer require tecnickcom/tcpdf`

<?php

namespace app\api\controller;

use think\facade\Env;
use think\facade\Db;
use TCPDF;

class FilesController extends BaseController
{
    public function index()
    {
        $url = 'uploads'.DIRECTORY_SEPARATOR.'paper'.DIRECTORY_SEPARATOR.'1.pdf';
        // 生成PDF
        $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
        $pdf->SetMargins(15, 15, 15);
        $pdf->SetFont('stsongstdlight', '', 12);
        $pdf->AddPage();
        $content = file_get_contents(cmf_get_domain());
        $pdf->writeHTML($content, true, false, true, false, '');
        $rootPath = public_path();

        $showType= 'F';//PDF输出的方式。I,在浏览器中打开;D,以文件形式下载;F,保存到服务器中;S,以字符串形式输出;E:以邮件的附件输出
        $filePath =  $rootPath . $url;
        $pdf->Output($filePath, $showType);

        $this->success('success',['v'=>$filePath]);
    }

}
?>