bdcgenerator/laravel-document-generator
Composer 安装命令:
composer require bdcgenerator/laravel-document-generator
包简介
This library I made to make it easy to generate documents to PDF with PhpWord and Laravel.
README 文档
README
This library is made to make it easy to generate documents from DOCX templates and convert them to PDF using PhpWord and LibreOffice, with support for dynamic templates, images, repeaters, and S3 upload.
Requirements
- PHP 8.1+
- Laravel 10 or 11
- LibreOffice installed on the server (
sofficecommand available) - PhpOffice PhpWord
- (Optional) AWS S3 configured in
filesystems.php
Installation
composer require bdcgenerator/laravel-document-generator php artisan vendor:publish --tag=bdcgenerator-config php artisan vendor:publish --tag=bdcgenerator-migrations php artisan migrate
ENV
LIBREOFFICE_BIN=/usr/bin/soffice
DOC_TEMP_DISK=local
DOC_UPLOAD_DISK=s3
DOC_UPLOAD_VIS=public
DOC_KEEP_LOCAL=false
USAGE (STATIC TEMPLATE)
use Document;
$result = Document::generate([
'template_path' => public_path('templates/SuratKeterangan.docx'),
'values' => [
'nama' => $user->name,
'alamat' => $user->address,
],
'image' => [
'key' => 'ttd_kepala',
'path' => storage_path('app/public/sign/kepala.png'),
'width' => 100,
'height' => 50,
],
'category' => 'surat',
'year' => date('Y'),
'filename' => 'surat_keterangan_'.$user->id,
'upload' => true,
]);
(Dynamic Template)
$result = Document::generateByKey('ijazah_v1', [
'context' => [
'category' => 'ijazah',
'year' => 2025,
'filename' => 'ijazah_'.$mahasiswa->NIM
],
'data' => $payload // structure matches your descriptor mapping
]);
Features
Static generation: Map placeholder values directly in code.
Dynamic templates: Store descriptor mapping in DB for flexible document definitions.
Image insertion: Insert images into DOCX placeholders.
Repeaters: Clone table rows or blocks for list data.
Conditional blocks: Delete or keep sections based on conditions.
PDF conversion: Uses LibreOffice CLI for accurate DOCX to PDF conversion.
S3 upload: Directly upload the generated PDF to S3.
bdcgenerator/laravel-document-generator 适用场景与选型建议
bdcgenerator/laravel-document-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bdcgenerator/laravel-document-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bdcgenerator/laravel-document-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-15