承接 ictsolutions/codeigniter-dompdf 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ictsolutions/codeigniter-dompdf

Composer 安装命令:

composer require ictsolutions/codeigniter-dompdf

包简介

Dompdf for CodeIgniter 4 framework.

README 文档

README

The CodeIgniter Dompdf Library is a wrapper that assists in generating PDFs using the Dompdf library within the CodeIgniter framework.

The Dompdf library is a popular PHP library that allows you to create PDF documents from HTML markup. It converts HTML and CSS into PDF format, allowing you to generate PDF files dynamically based on your web application's data.

Using the CodeIgniter Dompdf Library, you can easily generate PDFs by passing HTML content or views to the library's methods. The library takes care of rendering the HTML, applying CSS styles, and converting it into a downloadable PDF file.

PHP CodeIgniter

Installation

Installation is done through Composer.

composer require ictsolutions/codeigniter-dompdf

Configuration

The library's default behavior can be overridden or augmented by its config file. Copy examples/Pdf.php to app/Config/Pdf.php and follow the instructions in the comments. If no config file is found the library will use its default. In the Breadcrumb class, you can set the following configuration options:

showWarnings (boolean, default: false)

If set to true, an Exception will be thrown on warnings from dompdf.

convertEntities (boolean, default: true)

If set to true, Dejavu Sans font is used. However, this font does not have glyphs for certain entities like € and £. If you need to display these characters correctly, you can set this option to false.

defaultMediaType (string, default: 'screen')

This option specifies the target media view which should be rendered into the PDF. Possible values are:

  • screen
  • tty
  • tv
  • projection
  • handheld
  • print
  • braille
  • aural
  • all

defaultPaperSize (string, default: 'a4')

This option specifies the default paper size for the PDF document. It accepts standard paper sizes like 'letter', 'legal', 'A4', etc.

defaultPaperOrientation (string, default: 'portrait')

This option specifies the default paper orientation for the PDF document. Possible values are 'portrait' and 'landscape'.

defaultFont (string, default: 'serif')

This option specifies the default font family to be used if no suitable fonts can be found. The font must exist in the font folder.

fontHeightRatio (integer, default: 1)

This option applies a ratio to the font's height to make it more similar to browsers' line height.

dpi (integer, default: 96)

This option specifies the DPI (dots per inch) setting for images and fonts. This determines the default rendering resolution for the PDF document.

isPhpEnabled (boolean, default: false)

If set to true, DOMPDF will automatically evaluate inline PHP code contained within <script type="text/php"> ... </script> tags.

Note: Enabling this option for untrusted documents can be a security risk.

isRemoteEnabled (boolean, default: true)

If set to true, DOMPDF will access remote sites for images and CSS files as required.

Note: Enabling this option can be a security risk, especially when combined with other options like isPhpEnabled.

isJavascriptEnabled (boolean, default: true)

If set to true, DOMPDF will automatically insert JavaScript code contained within <script type="text/javascript"> ... </script> tags.

Usage

First, we need to load the Pdf Library:

$dompdf = new \IctSolutions\CodeIgniterDompdf\Pdf();

After creating an instance of Dompdf, we can setup the PDF properties:

$dompdf->set_option('isRemoteEnabled', TRUE);
$dompdf->setPaper('A4', 'landscape');

Then, we use it to load Html content:

$html = '<h1>Welcome to PDF Generator</h1>';
$dompdf->loadHtml($html);

We can render the Html content:

$dompdf->render();

And finally, we can stream the output:

$dompdf->stream('welcome.pdf', array("Attachment"=>0)); // stream to client side

Example: Creating a CodeIgniter Project with Dompdf

Here are general guideline steps to include Dompdf library in CodeIgniter:

  1. Install the library through Composer in your project:
composer require ictsolutions/codeigniter-dompdf
  1. When you need to create a PDF, load the library:
$dompdf = new \IctSolutions\CodeIgniterDompdf\Pdf();
  1. Use the library to create PDFs. The following example shows creating a PDF from a view:
$htmlContent = $this->load->view('pdf_view',$data,TRUE);
$dompdf->loadHtml($htmlContent);
$dompdf->render();
$dompdf->stream("welcome.pdf", array("Attachment"=>0));

In this example, 'pdf_view' would be a view file that contains your HTML structure, and $data would be any data you want to pass to the view. The output would be streamed to the client with the filename welcome.pdf. If you set the Attachment option to 1, the PDF file would be downloaded by the client rather than displayed in the browser. Please modify and adjust these examples according to your actual project and codebase.

License

This project is licensed under the MIT License - see the LICENSE file for details.

ictsolutions/codeigniter-dompdf 适用场景与选型建议

ictsolutions/codeigniter-dompdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.27k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「codeigniter」 「dompdf」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ictsolutions/codeigniter-dompdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ictsolutions/codeigniter-dompdf 我们能提供哪些服务?
定制开发 / 二次开发

基于 ictsolutions/codeigniter-dompdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-07