定制 maxchene/kirby-pdf 二次开发

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

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

maxchene/kirby-pdf

Composer 安装命令:

composer require maxchene/kirby-pdf

包简介

Kirby plugin that a PDF engine to convert HTML to PDF

README 文档

README

This plugin allow you to choose a PDF engine to render HTML as PDF.

WIP

For now this plugin is only working with WkHtmlToPdf installed on your server.

More engines will be coming soon: tcpdf, dompdf, mpdf.

Installation

Download and copy this repository into site/plugins/pdf

Or use composer : composer require maxchene/kirby-pdf

Rendering

Rendering with current template

This is the simplest render. PDF engine will parse the current page with her current template and css to render the PDF file.

For this rendering, you might want to use print media queries and page media query to fit your needs.

Dedicated pdf template

Sometimes rendering a pdf with media queries can be tricky, and sometimes you'll want a different rendering between HTML page and PDF file for the same data.

In this case, you can configure a dedicated template for the PDF rendering using a custom css file and custom HTML tree.

To activate dedicated template, you have to create a new template with the same name as your page template in the pdf subdirectory of your templates folder.

This is an example with a recipe page template :

├── snippets
├── templates
│   ├── pdf
│   │   ├── recipe.php   <- used to render the PDF file
│   ├── recipe.php       <- used to render the HTML page

So, in the templates/pdf/recipe.php, you can use a totally different layout and css to render the PDF file.

Configuration

To configure kirby pdf plugin, add a maxchene.kirbypdf entry in your site/config/config.php

'maxchene.kirby-pdf' => [
    'margin' => [
        'bottom' => 10,         // margins unit is millimeter(mm)
        'left' => 10,
        'right' => 10,
        'top' => 10,
    ],
    'orientation' => 'portrait' //either 'portrait' or 'landscape'
]

Orientation can be either portrait or landscape, default is portrait.

Note that margins are in millimeters (mm).

How to use in your templates

Here is a quick example of how you can use page to PDF in your template:

<h1>Guacamole recipe</h1>

<a href="<?= $page->pdfUrl();?>" target="_blank">
  Here is a link to pdf file, will open in new browser tab
</a>


<a href="<?= $page->pdfUrl();?>" download="my-pdf-filename.pdf">
  This will force PDF download with provided filename
</a>

TODO

  • Add more PDF engines
  • Allow users to disable PDF rendering by page template

maxchene/kirby-pdf 适用场景与选型建议

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

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

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

围绕 maxchene/kirby-pdf 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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