定制 bdcgenerator/laravel-document-generator 二次开发

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

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

bdcgenerator/laravel-document-generator

最新稳定版本:v0.16

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固