IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> laravel MPDF打印 -> 正文阅读

[PHP知识库]laravel MPDF打印

最近有一个需求需要在网页上打开pdf 直接可以打印那种

因为我用的是laravel 框架
于是就找到了 carlos-meneses/laravel-mpdf
github 地址 https://github.com/carlos-meneses/laravel-mpdf
码云地址 https://toscode.gitee.com/bilier/laravel-mpdf


一、composer 安装 laravel-mpdf

composer require carlos-meneses/laravel-mpdf

composer 如何安装

二、使用步骤

1. 在 config/app.php 文件 添加

'providers' => [
  // ...
  Meneses\LaravelMpdf\LaravelMpdfServiceProvider::class
]
'aliases' => [
  // ...
  'PDF' => Meneses\LaravelMpdf\Facades\LaravelMpdf::class
]

2. 新建 config/pdf.php

代码如下(示例):

<?php
return [
    /*
     * Logging
     * This will log to a file in storage_path('logs/pdf.log')
     * To use Laravel default logging set to default
     * Comment out or set to null to disable logging
     */
    'logging'           => 'custom',
    // ConstructorParams
    'mode'              => 'zh-cn',    // 中文显示
    'format'            => 'A4',
    'default_font_size' => 0,
    'default_font'      => '',
    'margin_left'       => 15,
    'margin_right'      => 15,
    'margin_top'        => 16,
    'margin_bottom'     => 16,
    'margin_header'     => 9,
    'margin_footer'     => 9,
    'orientation'       => 'P',
    /**
     * Set custom temporary directory
     * The default temporary directory is vendor/mpdf/mpdf/tmp
     *
     * @see https://mpdf.github.io/installation-setup/folders-for-temporary-files.html
     * Comment the following line to keep the temporary directory
     */
    'tempDir' => storage_path('app/pdf/tmp'), // absolute path
    /**
     * Custom Fonts
     *  1) Add your custom fonts to one of the directories listed under
     * 'fontDir' in which Mpdf will look for fonts
     *
     * 2) Define the name of the font and its configuration under the array 'fontdata'
     *
     * @see https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
     */
    // List of Directories Containing fonts (use absolute path)
    'fontDir'           => [
        storage_path('app/pdf/fonts'), // absolute path
        // add extra directory here
    ],
    // Fonts Configurations
    'fontdata'          => [
        // font name should be lower-case and contain no spaces
        'customfontname' => [
            'R'          => 'RegularCustomFont.ttf',
            'B'          => 'BoldCustomFont.ttd',
            'useOTL'     => 255,
            'useKashida' => 75,
        ],
        // lower-case and contain no spaces
        'arabic-font' => [
            'R'          => 'Montserrat-Arabic-Regular.ttf',
            'B'          => 'Montserrat-Arabic-Bold.ttf',
            'useOTL'     => 255,
            'useKashida' => 75,
        ],
        'shabnam' => [
            'R'          => 'Shabnam.ttf',
            'useOTL'     => 255,
            'useKashida' => 75,
        ],
    ],
];

3. 使用

use PDF;
class ReportController extends Controller {
  public function generate_pdf()
  {
 	//loadView(视图,数据);
    $pdf =   PDF::loadView('member.pdf',['data'=>$data]);
	return $pdf->stream();//直接在网页显示
	// return $pdf->download('/pdf文件路径.pdf');//下载
  }
}

视图示例 resources\views\member\pdf.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <table style="border-collapse: collapse; width: 900px; height: 56px; font-family: SimHei; font-size: 18px; position: relative;" id="pdf">
        <tbody>
            <tr style="text-align:left;" class="firstRow">
                <td style="text-align:left;" colspan="5">
                    {{$data['order']['order_num'] ?? ''}}
                </td>
            </tr>
            <tr style="height:75px;text-align:center;" class="firstRow">
                <td style="text-align:left;" colspan="3">
                    <img src="static/img/pdflogo.png"/>
                </td>
                <td style="text-align:right" colspan="2">
                {{  date('Y').'年'.date('m').'月'.date('d').'日'}}
                </td>
            </tr>
            <tr style="height:50px;text-align:center;" class="firstRow">
                <td style="font-weight: bold;font-size:40px;text-align:center;" colspan="5">
                    買取申込書
                </td>
            </tr>
            <tr style="height:100px;">
                <td style="border:2px solid;" colspan="5">
                    <table style="width:900px;border:0px;text-align:center;" border="1" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:20%;background:#C0C0C0;">ふりがな</td>
                            <td style="width:30%">{{$data['examine']['name'] ?? ''}}</td>
                            <td style="width:10%;background:#C0C0C0;">性別</td>
                            <td style="width:10%">{{$data['examine']['sex']==1 ?'男':'女' }}</td>
                            <td style="width:30%;background:#C0C0C0;">生年月日</td>
                        </tr>

                        <tr>
                            <td style="background:#C0C0C0;">お名前</td>s
                            <td>{{$data['examine']['name'] ?? ''}}</td>
                            <td style="background:#C0C0C0;">年齢</td>
                            <td>{{$data['examine']['age'] ?? ''}}</td>
                            <td>西暦 {{$data['examine']['birth'] ?? ''}}</td>
                        </tr>
                        <tr>
                            <td style="background:#C0C0C0;">ご住所〒</td>
                            <td colspan="4">{{$data['examine']['addr'] ?? ''}}</td>
                        </tr>

                        <tr>
                            <td style="background:#C0C0C0;">お電話番号</td>
                            <td>{{$data['member']['mobile'] ?? ''}}</td>
                            <td colspan="2" rowspan="2" style="background:#C0C0C0;">ご職業</td>
                            <td rowspan="2">{{$data['examine']['occupation'] ?? ''}}</td>
                        </tr>

                        <tr>
                            <td style="background:#C0C0C0;">メールアドレス</td>
                            <td>{{$data['member']['email'] ?? ''}}</td>
                        </tr>

                    </table>
                </td>
            </tr>
            <tr style="height:32px;text-align:left;">
                <td style="font-weight: normal;width:15%;">
                    【必要本人確認種類】
                </td>
                <td style="font-weight: normal; font-size:10px;color:red;width:85%;" colspan="4">
                ※申込者本人の身分証に限ります<br/>
                ※古物営業法により取引相手の義務付けられている為、本人確認種類は氏名、現住所、生年月日が記載されているものをご用意下さい。
                </td>
            </tr>
            <tr style="height:200px">
                <td style="border:2px solid;" colspan="5">
                    <table style="width:900px;border:0px;text-align:center;" border="1" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="background:#C0C0C0;" colspan="3">銀行振込</td>
                        </tr>
                        <tr>
                            <td style="text-align:left;" colspan="3">
                            &nbsp;&nbsp;?住民票原本(原本)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            ?印鑑証明書原本(原本)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            ?戸籍の謄本原本(原本)のいずれか
                            </td>
                        </tr>
                        <tr>
                            <td style="background:#C0C0C0;" colspan="2">お振込先銀行名</td>
                            <td style="background:#C0C0C0;">支店名</td>
                        </tr>
                        <tr>
                            <td colspan="2">{{$data['examine']['bank_name'] ?? ''}}</td>
                            <td>{{$data['examine']['branch_name'] ?? ''}}</td>
                        </tr>
                        <tr>
                            <td style="width:20%;background:#C0C0C0;">口座種別</td>
                            <td style="width:40%;background:#C0C0C0;">口座番号</td>
                            <td style="width:40%;background:#C0C0C0;">口座名義</td>
                        </tr>

                        <tr>
                            <td>{{$data['examine']['port_category'] ?? ''}}</td>
                            <td>{{$data['examine']['slogans'] ?? ''}}</td>
                            <td>{{$data['examine']['name_mouth'] ?? ''}}</td>
                        </tr>
                        <tr>
                            <td style="text-align:left;background:#C0C0C0;border:0px;" colspan="3">?法人の場合</td>
                        </tr>

                        <tr>
                            <td colspan="3" style="text-align:left;">
                            &nbsp;&nbsp;?登記事項証明書(原本)&nbsp;&nbsp;
                            &nbsp;&nbsp;?印鑑登録証明書(原本)&nbsp;&nbsp;
                            <span style="color:red;font-size:10px;">※発行より3ヶ月以内のもの</span> のいずれか
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>
            <tr style="height:32px">
                <td style="font-weight: bold;" colspan="5">
                【商品内容】
                </td>
            </tr>
            <tr style="height:170px">

                <td style="border:2px solid;" colspan="5">
                    <table style="width:900px;border:0px;text-align:center;" border="1" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:20%;background:#C0C0C0;">商品名</td>
                            <td style="width:20%;background:#C0C0C0;">品番</td>
                            <td style="width:10%;background:#C0C0C0;">状態</td>
                            <td style="width:15%;background:#C0C0C0;">サイズ</td>
                            <td style="width:15%;background:#C0C0C0;">査定値段</td>
                            <td style="width:10%;background:#C0C0C0;">数量</td>
                            <td style="width:10%;background:#C0C0C0;">合計</td>
                        </tr>
                        <?php echo $data['html'];?>
                        <tr>
                            <td style="color:red;font-size:10px;text-align:left;" colspan="4"></td>
                            <td>総合計</td>
                            <td>{{$data['order']['num'] ?? ''}}</td>
                            <td>{{number_format($data['order']['price']) ?? ''}}</td>
                        </tr>

                    </table>
                </td>
            </tr>
            <tr><td colspan="5">&nbsp;</td> </tr>
            <tr style="height:120px;border:1px solid;">
                <td colspan="5" style="font-size:12px;">
                    <b style="color:red;">【ご確認事項】</b></br>
                    ?18才未満のお客様は買取行っていません。</br>
                    ?盗難品、偽造品は買取できません。(上記事項に該当したばあい返金、損害賠償請求を行い、警察署へ被害届を提出致します。)</br>
                    ?ご本人確認のため、身分証を確認致します。(確認できない場合お引き取りできません。)</br>
                    ?買取成立後、(お振込後)のご返品は出来ませんので、ご注意ください。</br>
                    ?配送時の傷や破損、紛失は一切保証出来ません。</br>
                    (尚、不正転売目的にて入手した商品の買取を行うことは出来兼ねます。何卒ご了承ください。)</br>
                    ?お客様の個人情報の保護に関する法律、その他法令を尊守し、また「個人情報保護方針」を定め、個人情報の適切な取り扱いを行います。</br>
                    ?お客様にご提供頂きました本同意書の個人情報は、下記目的のために利用致します。</br>
                    &nbsp;①買取申込?同意の確認及び所有者の確認。②古物営業法に則った売買履歴の管理。

                </td>
            </tr>
            <tr><td colspan="5">&nbsp;</td> </tr>
            <tr style="height:80px;text-align:left;font-size:13px;">
               
                <td style="text-align:right;font-weight:bold;width:20%" colspan="2">
                    ご名欄 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
                    {{$data['examine']['signature'] ?? ''}}
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2022-09-24 20:37:31  更:2022-09-24 20:37:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/5 4:03:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码