bdcgenerator/laravel-document-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bdcgenerator/laravel-document-generator

最新稳定版本:v0.1.4

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

Latest Version on Packagist Total Downloads

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 (soffice command 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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-15