当前位置: 首页 > wzjs >正文

网站的功能需求聊城建设学校毕业证

网站的功能需求,聊城建设学校毕业证,苏州保洁公司钟点工,网站建设公司合肥一.导出pdf文件,首先要安装相关的类库文件,我用的是dompdf类库。 1.安装类库文件: composer require dompdf/dompdf 2.引入类库文件到你的控制器中,创建方法: public function generatePdf(){//你需要打印的查询内容…

一.导出pdf文件,首先要安装相关的类库文件,我用的是dompdf类库。

 1.安装类库文件:

composer require dompdf/dompdf

2.引入类库文件到你的控制器中,创建方法:

    public function generatePdf(){//你需要打印的查询内容$data = ['name' => '烦烦烦','content' => '哈哈哈计划经济','img' => 'https:://www.tupian.com/upload/name.png'];// 实例化 Dompdf 对象$options = new Options();// 重点设置字体$options->setDefaultFont('SimSun');$dompdf = new Dompdf($options);// 设置 HTML 内容$html = $this->getPdfContent($list); // 自定义获取数据并生成 HTML 的方法// 加载 HTML 到 Dompdf$dompdf->loadHtml($html);$dompdf->setPaper('A4', 'portrait');// 渲染 PDF$dompdf->render();// 输出 PDF 文件到浏览器$dompdf->stream("/report.pdf", array("Attachment" => true)); // 可以设置为 true 来强制下载return $this->success('ok');}//pdf的html文件private function getPdfContent($data){// 获取数据并生成 HTML 字符串
//        $data = YourModel::all(); // 替换为你的数据获取逻辑$html = '<meta charset="UTF-8">';$html = '<html><head><style>table { width: 100%; border-collapse: collapse; } td, th { border: 1px solid black; padding: 8px; text-align: left; }</style></head><body>';$html .= '<h1>记录</h1>';$html .= '<table>';//        foreach ($data as $row) {$html .= '<tr><td><b></b></td><td></td></tr>';$html .= "<tr><td>名称</td><td>{$data->name}</td></tr>"; // 根据你的数据结构调整单元格内容$html .= "<tr><td>使用内容</td><td>{$data->content}</td></tr>"; $html .= "<tr><td>图片</td><td><img src='{$data->img}' width='100' height='100'></img></td></tr>";//        }$html .= '</table></body></html>';return $html;}

二. 这时候你去访问生成pdf文件,若输出数据为中文,则会显示乱码。需要引用字体库文件。
 1) 新建load_font.php放到项目跟目录,跟verdor同级:

<?php
// 1. [Required] Point to the composer or dompdf autoloader
require_once "vendor/autoload.php";// 2. [Optional] Set the path to your font directory
//    By default dompdf loads fonts to dompdf/lib/fonts
//    If you have modified your font directory set this
//    variable appropriately.
//$fontDir = "lib/fonts";// *** DO NOT MODIFY BELOW THIS POINT ***use Dompdf\Dompdf;
use Dompdf\CanvasFactory;
use Dompdf\Exception;
use Dompdf\FontMetrics;
use Dompdf\Options;use FontLib\Font;/*** Display command line usage*/
function usage() {echo <<<EOD
Usage: {$_SERVER["argv"][0]} font_family [n_file [b_file] [i_file] [bi_file]]
font_family:      the name of the font, e.g. Verdana, 'Times New Roman',monospace, sans-serif. If it equals to "system_fonts", all the system fonts will be installed.
n_file:           the .ttf or .otf file for the normal, non-bold, non-italicface of the font.
{b|i|bi}_file:    the files for each of the respective (bold, italic,bold-italic) faces.
If the optional b|i|bi files are not specified, load_font.php will search
the directory containing normal font file (n_file) for additional files that
it thinks might be the correct ones (e.g. that end in _Bold or b or B).  If
it finds the files they will also be processed.  All files will be
automatically copied to the DOMPDF font directory, and afm files will be
generated using php-font-lib (https://github.com/PhenX/php-font-lib).
Examples:
./load_font.php silkscreen /usr/share/fonts/truetype/slkscr.ttf
./load_font.php 'Times New Roman' /mnt/c_drive/WINDOWS/Fonts/times.ttf
EOD;
exit;
}if ( $_SERVER["argc"] < 3 && @$_SERVER["argv"][1] != "system_fonts" ) {usage();
}$dompdf = new Dompdf();
if (isset($fontDir) && realpath($fontDir) !== false) {$dompdf->getOptions()->set('fontDir', $fontDir);
}/*** Installs a new font family* This function maps a font-family name to a font.  It tries to locate the* bold, italic, and bold italic versions of the font as well.  Once the* files are located, ttf versions of the font are copied to the fonts* directory.  Changes to the font lookup table are saved to the cache.** @param Dompdf $dompdf      dompdf main object * @param string $fontname    the font-family name* @param string $normal      the filename of the normal face font subtype* @param string $bold        the filename of the bold face font subtype* @param string $italic      the filename of the italic face font subtype* @param string $bold_italic the filename of the bold italic face font subtype** @throws Exception*/
function install_font_family($dompdf, $fontname, $normal, $bold = null, $italic = null, $bold_italic = null) {$fontMetrics = $dompdf->getFontMetrics();// Check if the base filename is readableif ( !is_readable($normal) )throw new Exception("Unable to read '$normal'.");$dir = dirname($normal);$basename = basename($normal);$last_dot = strrpos($basename, '.');if ($last_dot !== false) {$file = substr($basename, 0, $last_dot);$ext = strtolower(substr($basename, $last_dot));} else {$file = $basename;$ext = '';}if ( !in_array($ext, array(".ttf", ".otf")) ) {throw new Exception("Unable to process fonts of type '$ext'.");}// Try $file_Bold.$ext etc.$path = "$dir/$file";$patterns = array("bold"        => array("_Bold", "b", "B", "bd", "BD"),"italic"      => array("_Italic", "i", "I"),"bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"),);foreach ($patterns as $type => $_patterns) {if ( !isset($$type) || !is_readable($$type) ) {foreach($_patterns as $_pattern) {if ( is_readable("$path$_pattern$ext") ) {$$type = "$path$_pattern$ext";break;}}if ( is_null($$type) )echo ("Unable to find $type face file.\n");}}$fonts = compact("normal", "bold", "italic", "bold_italic");$entry = array();// Copy the files to the font directory.foreach ($fonts as $var => $src) {if ( is_null($src) ) {$entry[$var] = $dompdf->getOptions()->get('fontDir') . '/' . mb_substr(basename($normal), 0, -4);continue;}// Verify that the fonts exist and are readableif ( !is_readable($src) )throw new Exception("Requested font '$src' is not readable");$dest = $dompdf->getOptions()->get('fontDir') . '/' . basename($src);if ( !is_writeable(dirname($dest)) )throw new Exception("Unable to write to destination '$dest'.");echo "Copying $src to $dest...\n";if ( !copy($src, $dest) )throw new Exception("Unable to copy '$src' to '$dest'");$entry_name = mb_substr($dest, 0, -4);echo "Generating Adobe Font Metrics for $entry_name...\n";$font_obj = Font::load($dest);$font_obj->saveAdobeFontMetrics("$entry_name.ufm");$font_obj->close();$entry[$var] = $entry_name;}// Store the fonts in the lookup table$fontMetrics->setFontFamily($fontname, $entry);// Save the changes$fontMetrics->saveFontFamilies();
}// If installing system fonts (may take a long time)
if ( $_SERVER["argv"][1] === "system_fonts" ) {$fontMetrics = $dompdf->getFontMetrics();$files = glob("/usr/share/fonts/truetype/*.ttf") +glob("/usr/share/fonts/truetype/*/*.ttf") +glob("/usr/share/fonts/truetype/*/*/*.ttf") +glob("C:\\Windows\\fonts\\*.ttf") +glob("C:\\WinNT\\fonts\\*.ttf") +glob("/mnt/c_drive/WINDOWS/Fonts/");$fonts = array();foreach ($files as $file) {$font = Font::load($file);$records = $font->getData("name", "records");$type = $fontMetrics->getType($records[2]);$fonts[mb_strtolower($records[1])][$type] = $file;$font->close();}foreach ( $fonts as $family => $files ) {echo " >> Installing '$family'... \n";if ( !isset($files["normal"]) ) {echo "No 'normal' style font file\n";}else {install_font_family($dompdf, $family, @$files["normal"], @$files["bold"], @$files["italic"], @$files["bold_italic"]);echo "Done !\n";}echo "\n";}
}
else {call_user_func_array("install_font_family", array_merge( array($dompdf), array_slice($_SERVER["argv"], 1) ));
}

2)下载simsun.ttf文件放到根目录下:
3)执行命令:

//必须执行,很重要
php load_fount.php "SimSun" SimSun.ttf

4)添加设置字体的引用,如图一:

        // 重点设置字体$options->setDefaultFont('SimSun');

参考文档:php|thinkphp pdf 导出中文乱码 解决办法 #php导出 pdf中文乱码_我自横刀向天笑的技术博客_51CTO博客三.这时候,你想要导出的数据还有图片怎么办

1)将图片转换为base64的格式输出

$image = 'data:image/jpeg;base64,' . base64_encode(file_get_contents($data['img']));

参考文档:php生成pdf图片不显示怎么办-PHP问题-PHP中文网


文章转载自:

http://aXUDtlMQ.zxwqt.cn
http://hVqWN7XX.zxwqt.cn
http://RbfYsCSI.zxwqt.cn
http://glzvlZmd.zxwqt.cn
http://N6Ergnfe.zxwqt.cn
http://yl4G8gK2.zxwqt.cn
http://e1wBJr02.zxwqt.cn
http://horB1dcq.zxwqt.cn
http://C7oxmXaH.zxwqt.cn
http://MxOJEecA.zxwqt.cn
http://naAKyB9K.zxwqt.cn
http://chSafhNh.zxwqt.cn
http://WpBWGjgL.zxwqt.cn
http://MkeRDNzG.zxwqt.cn
http://Q1dwwgh3.zxwqt.cn
http://FzUh8BWJ.zxwqt.cn
http://CKNWHvxp.zxwqt.cn
http://JwEwHewO.zxwqt.cn
http://iPYag7vU.zxwqt.cn
http://aoeHQvOh.zxwqt.cn
http://lkXW9E8L.zxwqt.cn
http://weasY2Yw.zxwqt.cn
http://WUvLCLcW.zxwqt.cn
http://fwAVfkus.zxwqt.cn
http://PnHqnRCl.zxwqt.cn
http://UDCU7Jlv.zxwqt.cn
http://OEQXo1UN.zxwqt.cn
http://0Fx8YvEF.zxwqt.cn
http://uv0smXlc.zxwqt.cn
http://HpltgV2d.zxwqt.cn
http://www.dtcms.com/wzjs/764946.html

相关文章:

  • 做竞拍网站合法吗深圳网站建设哪家
  • 怀柔石家庄网站建设自己如何做企业网站
  • 网站涉及敏感视频等该怎么做logo和网站主色调
  • 米东区成业建设集团公司网站网站开发外文翻译
  • 永年做网站多少钱dz论坛做视频网站教程
  • 网站建设框架构建个人微信公众平台怎么用
  • seo网站运营网站做标题有用吗
  • 门户网站建设工作方案免费建手机个人网站
  • 帮一个企业做网站流程网络营销的成功案例
  • 作品集模板网站久久营销网站
  • 网站开发代理dw网页制作实例教程
  • 外国网站 dns解析失败网站网页设计的组成
  • 在百度做网站多少钱网站推广的方法有哪些?
  • 手机版网站建设多少钱初次创业开什么店合适
  • 怎么找到合适的网站建设商推销产品怎样才能打动客户
  • 网站建设海淀区博客移植wordpress
  • 长沙做一个网站要多少钱网络营销的常用工具
  • 淘客网站建设视频国家企业信用查询信息系统(全国)
  • 办网站费用多少钱安卓开发网站开发
  • 使用angularjs的网站去招聘网站做顾问
  • 广州做礼物的网站asp网站水印支除
  • 焦作网站建设哪家正规做网站需要的知识
  • 用django怎么做网站微信小程序游戏手游排行榜
  • 电子产品网站建设 实训报告上海什么公司最有名
  • 苏州做网站海口建设企业网站
  • 3d打印网站开发dedecms网站怎么搬家
  • 安仁做网站wordpress点击分享功能
  • 成都网站品牌设计ftp 网站
  • 创建自己的网站需要准备什么网站建设公司导航
  • 微网站开发框架企业网站怎么收录