1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /** * 使用文档 * https://wenku.baidu.com/view/ce3f52d950e2524de5187e20.html?sxts=1544025155358 * https://wenku.baidu.com/view/9352b049852458fb770b5688.html */ include_once (APPLICATION_PATH. '/application/library/Pdf/Config/tcpdf_config_wjy.php' ); include_once (APPLICATION_PATH. '/application/library/Pdf/Lib/include/tcpdf_fonts.php' ); include_once (APPLICATION_PATH. '/application/library/Pdf/Lib/tcpdf.php' ); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8' , true); //设置文件信息 $pdf ->SetCreator(PDF_CREATOR); $pdf ->SetAuthor( 'Nicola Asuni' ); $pdf ->SetTitle( 'TCPDF Example 001' ); $pdf ->SetSubject( 'TCPDF Tutorial' ); $pdf ->SetKeywords( 'TCPDF, PDF, example, test, guide' ); //设置页眉页脚 $pdf ->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE. ' 001' , PDF_HEADER_STRING, array (0,64,255), array (0,64,128)); $pdf ->setFooterData( array (0,64,0), array (0,64,128)); // set header and footer fonts $pdf ->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '' , PDF_FONT_SIZE_MAIN)); $pdf ->setFooterFont(Array(PDF_FONT_NAME_DATA, '' , PDF_FONT_SIZE_DATA)); //设置默认等宽字体 $pdf ->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //设置页面边幅 $pdf ->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //设置纸张头部 $pdf ->SetHeaderMargin(PDF_MARGIN_HEADER); //设置纸张底部 $pdf ->SetFooterMargin(PDF_MARGIN_FOOTER); //设置自动分页符 $pdf ->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf ->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $l [ 'a_meta_charset' ] = 'UTF-8' ; $l [ 'a_meta_dir' ] = 'ltr' ; $l [ 'a_meta_language' ] = 'cn' ; // TRANSLATIONS -------------------------------------- $l [ 'w_page' ] = 'page' ; $pdf ->setLanguageArray( $l ); // --------------------------------------------------------- // set default font subsetting mode $pdf ->setFontSubsetting(true); // Set font // dejavusans is a UTF-8 Unicode font, if you only need to // print standard ASCII chars, you can use core fonts like // helvetica or times to reduce file size. // $pdf->SetFont('dejavusans', '', 14, '', true); // $pdf->SetFont('stsongstdlight', '', 20, '', true); $pdf ->SetFont( 'droid_sans_fallback' , '' , 20, '' , true); //自定义字体后面具体怎么制作 // Add a page // This method has several options, check the source code documentation for more information. $pdf ->AddPage(); // set text shadow effect $pdf ->setTextShadow( array ( 'enabled' =>true, 'depth_w' =>0.2, 'depth_h' =>0.2, 'color' => array (196,196,196), 'opacity' =>1, 'blend_mode' => 'Normal' )); // Set some content to print $html = '<h1>Welcome to <a href="TCPDF" style="text-decoration:none;background-color:#CC0000;color:black;"> <span style="color:black;">TC</span><span style="color:white;">PDF</span> </a>!</h1>' ; // Print text using writeHTMLCell() $pdf ->writeHTMLCell(0, 0, '' , '' , $html , 0, 1, 0, true, '' , true); $txt = "您好!" ; $pdf ->Write(20, $txt ); $image_file = K_PATH_IMAGES. 'logo_voucher.png' ; $pdf ->Image( $image_file , 10, 10, 15, '' , 'PNG' , '' , 'T' , false, 300, '' , false, false, 0, false, false, false); // test Cell stretching $pdf ->Cell(0, 0, 'TEST CELL STRETCH: no stretch' , 1, 1, 'C' , 0, '' , 0); $pdf ->Cell(0, 0, 'TEST CELL STRETCH: scaling' , 1, 1, 'C' , 0, '' , 1); $pdf ->Cell(0, 0, 'TEST CELL STRETCH: force scaling' , 1, 1, 'C' , 0, '' , 2); $pdf ->Cell(0, 0, 'TEST CELL STRETCH: spacing' , 1, 1, 'C' , 0, '' , 3); $pdf ->Cell(0, 0, 'TEST CELL STRETCH: force spacing' , 1, 1, 'C' , 0, '' , 4); $pdf ->Ln(15); $pdf ->Cell(45, 0, 'TEST CELL STRETCH: scaling' , 1, 1, 'C' , 0, '' , 1); $pdf ->Cell(45, 0, 'TEST CELL STRETCH: force scaling' , 1, 1, 'C' , 0, '' , 2); $pdf ->Cell(45, 0, 'TEST CELL STRETCH: spacing' , 1, 1, 'C' , 0, '' , 3); $pdf ->Cell(45, 0, 'TEST CELL STRETCH: force spacing' , 1, 1, 'C' , 0, '' , 4); // Image method signature: // Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Example of Image from data stream ('PHP rules') $imgdata = base64_decode ( 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==' ); // The '@' character is used to indicate that follows an image data stream and not an image file name $pdf ->Image( '@' . $imgdata ); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. $showType = 'D' ; //PDF输出的方式。I,在浏览器中打开;D,以文件形式下载;F,保存到服务器中;S,以字符串形式输出;E:以邮件的附件输出。 ob_end_clean(); $pdf ->Output( 'example_001.pdf' , $showType ); |