尊龙凯时人生就是搏

ÔõÑùʹÓÃThinkPHP6¾ÙÐÐPDFÎļþÌìÉú²Ù×÷£¿

Ëæ×ÅÐÅÏ¢»¯Ê±´úµÄÉú³¤ £¬pdfÎĵµÒѳÉΪһÑùƽ³£ÊÂÇ顢ѧϰÖв»¿É»òȱµÄÒ»²¿·Ö¡£¶øËæ×Å»¥ÁªÍø¡¢Òƶ¯»¥ÁªÍøµÄÆÕ¼° £¬ÒÔ¼°µç×Ó»¯Àú³ÌµÄÍƽø £¬pdfÎĵµµÄÓ¦Óó¡¾°Ò²ÔÚÒ»Ö±À©´ó £¬ºÃ±È±¨±í¡¢Ö¤Êé¡¢ÌõÔ¼µÈ·½Ãæ¡£Òò´Ë £¬Í¨¹ý´úÂëÌìÉúpdfÎĵµµÄʵÏÖ·½·¨Ò²³ÉΪÁËÐí¶àÆóÒµºÍСÎÒ˽ÈË¿ª·¢ÕßµÄÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp6¾ÙÐÐpdfÎļþÌìÉú²Ù×÷ £¬Ï£Íû¶ÔÄãÓÐËù×ÊÖú¡£

Ò»¡¢Å侰֪ʶ

ÔÚ×îÏÈÏÈÈÝÔõÑùʹÓÃThinkPHP6¾ÙÐÐPDFÎļþÌìÉú֮ǰ £¬ÐèÒªÎÒÃÇÏàʶһЩ»ù±¾µÄÅ侰֪ʶ£º

PDFÊÇʲô£¿

PDF£¨Portable Document Format£©¼´±ãЯʽÎĵµÃûÌà £¬ÊÇÓÉAdobe¹«Ë¾¿ª·¢µÄÒ»ÖÖÓÃÓÚÍøÂç´«ÊäºÍ´òÓ¡µÈ»·½ÚµÄµç×ÓÎļþÃûÌà £¬¿ÉÒÔÔÚÖݪֲÙ×÷ϵͳÉϱ»Ê¹Óá£Ëü¿ÉÒÔ½«Îĵµ¡¢Í¼ÐΡ¢Í¼Æ¬¡¢×ÖÌåµÈÔªËØÕûºÏµ½Ò»¸öÎļþÖС£

ThinkPHPÊÇʲô£¿

ThinkPHPÊÇÒ»¿î»ùÓÚPHPÓïÑԵĿªÔ´PHP¿ò¼Ü £¬ÊÇÖйú×îÊ¢ÐеÄPHP¿ò¼ÜÖ®Ò»¡£ThinkPHP×ñÕÕMVC¼Ü¹¹ £¬Ö§³ÖÖÚ¶àµÄÊý¾Ý¿â²Ù×÷¡¢Ä£°åÒýÇ桢ȨÏÞÈÏÖ¤¡¢»º´æµÈ¹¦Ð§ £¬¿ÉÒÔΪ¿ª·¢ÕßÌṩ¼òÆÓ¡¢¸ßЧ¡¢Çå¾²µÄ¿ª·¢ÌåÑé¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

PDFÎļþµÄÌìÉú·½·¨ÓÐÄÄЩ£¿

Ò»Ñùƽ³£À´Ëµ £¬PDFÎļþµÄÌìÉú·½·¨ÓÐÒÔϼ¸ÖÖ£º

£¨1£©ÊÖ¶¯±àдPDFÎļþ

£¨2£©Ê¹ÓõÚÈý·½¿âÌìÉúPDFÎļþ

£¨3£©Ê¹ÓÃÔÆЧÀÍÌìÉúPDFÎļþ

¶øÔÚÕâÈýÖÖ·½·¨ÖÐ £¬Ê¹ÓõÚÈý·½¿âÊÇ×îΪ³£ÓõÄÒ»ÖÖ £¬ÓÉÓÚÆä¾ßÓмòÆÓÒ×Óᢹ¦Ð§ÆëÈ«¡¢Ö§³ÖµÄÓïÑÔÒ²ºÜÆÕ±éµÈÓŵã¡£

¶þ¡¢Ê¹ÓÃThinkPHP6½¨ÉèÌìÉúPDFÎļþµÄ´úÂë

×°ÖÃTCPDF×é¼þ

ÔÚʹÓÃThinkPHP6¾ÙÐÐPDFÎļþÌìÉú֮ǰ £¬ÎÒÃÇÐèÒªÏÈ×°ÖÃTCPDF×é¼þ¡£TCPDFÊÇÒ»¿î¿ªÔ´µÄPHPÀà¿â £¬ÓÃÓÚÌìÉúPDFÎĵµ¡£¿ÉÒÔÔÚTCPDF¹ÙÍø»òGithubÉÏÏÂÔØTCPDF×é¼þ £¬²¢Æ¾Ö¤¹Ù·½ÎĵµµÄÖ¸Òý¾ÙÐÐ×°Öá£ÔÚÕâÀï £¬ÎÒÃÇ¿ÉÒÔͨ¹ýComposer×°ÖÃËü¡£

ÔÚterminal´°¿ÚÖÐÊäÈëÒÔÏÂÏÂÁîÐУº

composer require tecnickcom/tcpdf

µÇ¼ºó¸´ÖÆ

ÆÚ´ý×°ÖÃÍê³É £¬TCPDF×é¼þ»á×Ô¶¯Ìí¼Óµ½vendorĿ¼Ï¡£

½¨ÉèPDFÎļþÌìÉú¿ØÖÆÆ÷

ÔÚʹÓÃThinkPHP6¿ò¼ÜÌìÉúPDFÎļþ֮ǰ £¬ÐèÒª½¨ÉèÒ»¸öPDFÎļþÌìÉúµÄ¿ØÖÆÆ÷¡£ÔÚÏîÄ¿ÎļþĿ¼ÖÐ £¬Í¨¹ýÈçÏÂÏÂÁîÔÚapp/controllerĿ¼Ï½¨ÉèÒ»¸öGeneratepdf.phpÎļþ×÷Ϊ¿ØÖÆÆ÷£º

php think make:controller Generatepdf

µÇ¼ºó¸´ÖÆ

±àдPDFÎļþÌìÉú´úÂë

ÔÚÌìÉúPDFÎļþµÄ¿ØÖÆÆ÷ÖÐ £¬ÐèҪʵÏÖÌìÉúPDFÎļþµÄÒªÁì¡£ÔÚ´Ë £¬ÎÒÃÇÒÔÌìÉú¼òÆÓµÄPDFÎļþΪÀý¡£

ÔÚÌìÉúPDFÎļþµÄÒªÁìÖÐ £¬ÎÒÃÇÐèҪŲÓÃTCPDF¿â £¬²¢ÊµÏÖPDFÎļþµÄÌìÉú¡£ÎÒÃÇÐèÒª×öÒÔϼ¸¸ö°ì·¨£º

£¨1£©ÒýÈëTCPDF¿â

ÔÚ¿ØÖÆÆ÷ÖÐÒýÈëTCPDF¿â £¬²¢¾ÙÐгõʼ»¯¡£¿ÉÒ԰ݼûÒÔÏ´úÂë¾ÙÐÐʵÏÖ£º

use TCPDF;

class Generatepdf extends BaseController
{
    public function index()
    {
        // ÒýÈëTCPDF¿â
        require_once('../vendor/tecnickcom/tcpdf/tcpdf.php');

        // ³õʼ»¯¹¤¾ß
        $pdf = new TCPDF();
    }
}

µÇ¼ºó¸´ÖÆ

£¨2£©ÉèÖÃPDFÎļþ²ÎÊý

¿ÉÒÔÔÚÌìÉúPDFÎļþµÄÒªÁìÖÐ £¬ÉèÖÃPDFÎļþµÄÊôÐÔ¡¢Ò³Ãæ¾Þϸ¡¢Ò³ÃæÆ«ÏòµÈÊôÐÔ £¬¿ÉÒ԰ݼûÒÔÏ´úÂë¾ÙÐÐʵÏÖ£º

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator('ThinkPHP6');
$pdf->SetAuthor('×÷Õß');
$pdf->SetTitle('PDFÎĵµ');
$pdf->SetSubject('PDFÎĵµ Demo');
$pdf->SetKeywords('PDF, Demo, TCPDF, PHP');

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_RIGHT, PDF_MARGIN_TOP);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(PDF_MARGIN_BOTTOM);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetFont('cid0jp', '', 14);
$pdf->AddPage();

µÇ¼ºó¸´ÖÆ

£¨3£©ÏòPDFÎļþÖÐÌí¼ÓÄÚÈÝ

¿ÉÒÔʹÓÃTCPDF¿âÌṩµÄÒªÁì £¬ÏòPDFÎļþÖÐÌí¼ÓͼÏñ¡¢Îı¾¡¢±í¸ñµÈÔªËØ £¬¿ÉÒ԰ݼûÒÔÏ´úÂë¾ÙÐÐʵÏÖ£º

$pdf->Image('test.png', 10, 10, 150, 100, '', '', '', false, 300, '', false, false, 0, false, false, false);
$pdf->SetFont('cid0jp', '', 20);
$pdf->Cell(0,20,'Hello,World',0,1,'C');

$pdf->Ln();
$pdf->Ln();
$style = array('border' => 1, 'padding' => '2', 'header_line' => true, 'color' => array(255, 255, 255), 'font' => 'cid0jp', 'font_size' => 10);
$pdf->writeHTMlTable($data, $style);

µÇ¼ºó¸´ÖÆ

£¨4£©ÌìÉúPDFÎļþ

ÔÚÍê³ÉÏòPDFÎļþÖÐÌí¼ÓÔªËصIJÙ×÷ºó £¬»¹ÐèҪŲÓÃOutput()ÒªÁìÀ´Êä³öPDFÎļþ £¬ÔÚä¯ÀÀÆ÷ÉÏÏÔʾ»òÏÂÔØÎļþ¡£

$pdf->Output('test.pdf', 'D');

µÇ¼ºó¸´ÖÆ

Èý¡¢×ܽá

ͨ¹ýÒÔÉÏ°ì·¨ £¬ÎÒÃǾͿÉÒÔʹÓÃThinkPHP6¿ò¼Ü¶ÔPDFÎĵµ¾ÙÐÐÌìÉú¡£ÔÚ¿ª·¢Àú³ÌÖÐ £¬»¹ÐèҪעÖØPDFÎļþ·¾¶µÄÎÊÌâ £¬¿ÉÒÔʹÓÃÏà¶Ô·¾¶»ò¾ø¶Ô·¾¶À´½â¾ö¡£±ðµÄ £¬TCPDF¿â»¹ÌṩÁËÐí¶àÆäËûµÄ¹¦Ð§ £¬¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐÐŲÓúÍÀ©Õ¹¡£Ï£Íû±¾ÎÄÄÚÈݶÔʹÓÃThinkPHP6ÌìÉúPDFÎļþµÄ¿ª·¢ÕßÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP6¾ÙÐÐPDFÎļþÌìÉú²Ù×÷£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ