承接 snugcomponents/pdf-generator 相关项目开发

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

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

snugcomponents/pdf-generator

Composer 安装命令:

composer require snugcomponents/pdf-generator

包简介

SnugComponents component for generate PDF files.

README 文档

README

Library for generating PDF files using our API.

Introduction

This library is Nette extension for making requests to our microservice, which can generate PDF or screenshot from HTML code. If you want to use this extension, you need to have your own microservice.

Installation

Download

The best way to install snugcomponents/pdf-generator, is using Composer:

$ composer require snugcomponents/pdf-generator

Registering

Library is Nette ready, so you can register it in your config:

extensions:
	PdfGenerator: Snugcomponents\PdfGenerator\DI\PdfGeneratorExtension

Injecting

After registering there are two services, which you may be interested of. Both of them you can simply inject in your other services:

public function __construct(
	private \Snugcomponents\PdfGenerator\PdfFactory $pdfFactory,
	private \Snugcomponents\PdfGenerator\ScreenshotFactory $screenshotFactory,
) {
    parent::__construct();
    ...
}

Settings

All settings are required!!!

Library needs to be set up. You can do it by inserting following code into your private config:

PdfGenerator:
	url: 'https://pdfserver.com/' # URL of your microservice for generating PDFs
	tempDir: '%tempDir%'          # temp dir, where will be saved result from microservice
	username: 'username'          # username for Basic authentication
	password: 'password'          # password for Basic authentication

Usage

Usage is pretty simple:

PdfFactory:

$pdfFilename = $pdfFactory->create('<p>This is HTML to print</p>');    # send directly HTML which you need to print to PDF
$pdfFilename = $pdfFactory->create('https://htmlurl.com/');            # or send URL address of web page, which you need to be printed into PDF

In $pdfFilename you will have path to generated pdf. It will be saved in temp dir, which you provided by config. It is highly recommended to move file to another place.

ScreenshotFactory:

$imgFilename = $screenshotFactory->create(
    '<p>This is HTML to print</p>',     # HTML or URL
    1024,                               # width of printing screen - OPTIONAL
    768,                                # height of printing screen - OPTIONAL
);

In $imgFilename you will have path to generated jpg image. It will be saved in temp dir, which you provided by config. It is highly recommended to move file to another place.

Immediate file download

In case you need to download generated file without sawing it, you can do it by another service called FileResponse

Little example: (For Presenters only)

#[Inject] public PdfFactory $pdfFactory;
#[Inject] public \Snugcomponents\PdfGenerator\Responses\FileResponseFactory $fileResponseFactory;

public function actionGenerate(): void
{
    $filePath = $this->pdfFactory->create('<p>This is HTML to print</p>');
    $response = $this->fileResponseFactory->create(
        file:                   $filePath,          # path to file to download
        name:                   'document.pdf'      # name for downloaded file      - OPTIONAL
        contentType:            'application/pdf'   # Content-Type of file          - OPTIONAL
        forceDownload:          true,               # force download?               - OPTIONAL (default true)
        deleteFileWhenFinished: true,               # delete file after download?   - OPTIONAL (default false)
    );
    $this->sendResponse($response);
}

Setting up print to PDF

If you need to force your own setting for printing to PDF like remove border, hide images etc., then you can just add classic @media print css property to your stylesheet.

Conclusion

This extension requires PHP8.1, Nette3.1, and it is property of SnugDesign © 2023

snugcomponents/pdf-generator 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2022-06-08