定制 dimns/html-to-pdf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dimns/html-to-pdf

Composer 安装命令:

composer require dimns/html-to-pdf

包简介

Facade to convert html into pdf, uses the library mpdf

README 文档

README

Facade to convert html into pdf, uses the library mpdf

Install

composer require dimns/html-to-pdf

Methods

public HtmlToPdf::__construct ( string $path_to_folder [, array $mpdf_config ] )
  • $path_to_folder (string) Required - Path to the folder where the file will be placed

  • $mpdf_config (array) Optional - Redefining Mpdf settings

    Default settings:

    [
        'format'              => 'A4',
        'orientation'         => 'portrait',
        'default_font'        => 'arial',
        'setAutoTopMargin'    => 'stretch',
        'setAutoBottomMargin' => 'stretch',
    ]
public HtmlToPdf::create ( string $html_body [, string $html_header = null [, string $html_footer = null ]] ) : string
  • $html_body (string) Required - Content
  • $html_header (string) Optional - Header
  • $html_footer (string) Optional - Footer

Usage

Simple

Simple usage

<?php
use DimNS\HtmlToPdf\HtmlToPdf;
use Mpdf\MpdfException;

require_once 'vendor/autoload.php';

$htp = new HtmlToPdf(__DIR__);

$html_body = <<<HTML
<h1>
    Test html to pdf
</h1>
<p>
    <strong>Test</strong> <i>string</i> with <a href="https://domain.tld">link</a>
</p>
HTML;

try {
    echo $htp->create($html_body);
} catch (MpdfException $e) {
    echo $e->getMessage();
}

Advanced

Advanced usage

<?php
use DimNS\HtmlToPdf\HtmlToPdf;
use Mpdf\MpdfException;

require_once 'vendor/autoload.php';

$htp = new HtmlToPdf(__DIR__, [
    'format'         => 'A6',
    'orientation'    => 'landscape',
    'defaultCssFile' => '/path/to/style.css',
]);

$html_body = <<<HTML
<h1>
    Test html to pdf with header and footer
</h1>
<p>
    <strong>Test</strong> <i>string</i> with <a href="https://domain.tld">link</a>
</p>
HTML;

$html_header = <<<HTML
<p>
    <strong>This is header</strong>
</p>
<hr>
HTML;

$html_footer = <<<HTML
<hr>
<p>
    <strong>This is footer</strong>
</p>
HTML;

try {
    echo $htp->create($html_body, $html_header, $html_footer);
} catch (MpdfException $e) {
    echo $e->getMessage();
}

* style.css

.table {
    width: 100%;
}

.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

h1 {
    font-size: 16pt;
    color: green;
}

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2019-06-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固