定制 tungltdev/laravel-html-to-pdf 二次开发

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

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

tungltdev/laravel-html-to-pdf

Composer 安装命令:

composer require tungltdev/laravel-html-to-pdf

包简介

Convert a html string to a pdf string

README 文档

README

Installation:

$ composer require tungltdev/laravel-html-to-pdf

Features:

  • Convert an html string to a pdf string using wkhtmltopdf
  • Does not use temporary files

Basic usage:

use \Tungltdev\LARAVEL\HtmlToPdf;

try{

    $pdf = new HtmlToPdf('<html><body>Hi!<body></html>', '/usr/local/bin/wkhtmltopdf');

    header('Content-Type: application/pdf');

    echo $pdf->generate();

}
catch(Exception $e){
    echo $e->getMessage();
}

Advanced usage:

use \Tungltdev\LARAVEL\HtmlToPdf;

try{

    //Get your html string
    $html = file_get_contents('demo.html');

    // Path to wkhtmltopdf
    $pathToWkhtmltopdf = '/usr/local/bin/wkhtmltopdf';

    // Initialise
    $pdf = new HtmlToPdf($html, $pathToWkhtmltopdf);

    // Add a command before the wkhtmltopdf command
    $pdf->addBeforeCommand('unset DYLD_LIBRARY_PATH');

    // Add wkhtmltopdf parameters, second parameter is optional. See: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
    $pdf->setParam('grayscale');
    $pdf->setParam('orientation', 'landscape');

    // Execute
    $pdfString = $pdf->generate();

    // Show the generated pdf
    header('Content-Type: application/pdf');
    die($pdfString);

}
catch(Exception $e){
    echo $e->getMessage();
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-19