virdiggg/merge-files
Composer 安装命令:
composer require virdiggg/merge-files
包简介
Merge words, excel, PDF and image into a single PDF
README 文档
README
A lightweight PHP document merging library designed for practical backend workflows and legacy PDF compatibility handling.
This library allows multiple document types—including Word, Excel, images, and existing PDFs—to be consolidated into a single PDF output through a unified processing pipeline.
Unlike many PDF merging utilities that fail on newer PDF structures, this library automatically normalizes incompatible PDF versions using Ghostscript preprocessing to maintain compatibility with legacy PHP PDF ecosystems such as FPDF, FPDI, and mPDF.
Features
- Merge multiple file formats into a single PDF
- Automatic PDF compatibility normalization using Ghostscript
- Handles mixed document ingestion workflows
- Supports PDF metadata configuration
- Optional PDF permission restrictions
- Lightweight and framework-friendly
- Designed for internal systems and document automation pipelines
Supported File Types
- DOC
- DOCX
- XLS
- XLSX
- JPG
- JPEG
- PNG
Why Ghostscript Is Required
Many PHP PDF libraries such as FPDI, FPDF, and mPDF have limitations when importing or merging PDFs generated with newer PDF specifications (commonly PDF 1.5+).
This library automatically preprocesses incompatible PDFs through Ghostscript to:
- Normalize PDF versions
- Improve merge compatibility
- Prevent parser/import failures
- Avoid dependency on commercial PDF parser addons
Ghostscript is therefore a mandatory dependency.
Current Limitations
Embedded Images Inside DOC/DOCX
Images embedded inside .doc or .docx files are currently not supported during conversion.
Maintenance Status
This project is currently in maintenance mode.
No major feature updates are planned at the moment.
Required PHP Extension
The mbstring extension is required.
Installation
Install the package via Composer:
composer require virdiggg/merge-files
Ghostscript Installation
Install Ghostscript and ensure the gs command is globally accessible from your terminal or command prompt.
Official installation guide:
https://ghostscript.readthedocs.io/en/latest/Install.html
Verify installation:
gs
Expected output:
GPL Ghostscript 10.xx.x
GS>
Basic Usage
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Virdiggg\MergeFiles\Merge; try { $mf = new Merge(); $mf->setAuthor('Me'); $mf->setCreator('Also Me'); $mf->setOutputName('mergedpdf.pdf'); $mf->setOutputPath(__DIR__ . '/output/'); $mf->setTitle('Merged PDF'); $mf->setSubject('Merged PDF'); // Optional // $mf->setKeywords(['pdf', 'word', 'excel', 'image']); // Required if permissions are used // $mf->setPassword('password'); // Optional permissions // $mf->setPermissions(['copy']); $files = [ __DIR__.'/input/new_pdf.pdf', __DIR__.'/input/Book1.xlsx', __DIR__.'/input/download.pdf', __DIR__.'/input/word.docx', __DIR__.'/input/Wikipedia-logo-v2.png' ]; $mf->mergeToPDF($files); } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
PDF Permissions
You may configure PDF permissions using the following options.
Passing an empty array [] will disable all permissions, preventing actions such as copying, printing, modifying, or extracting content from the generated PDF.
Available permissions:
copyprintmodifyannot-formsfill-formsextractassembleprint-highres
Example:
$mf->setPermissions([ 'copy', 'print' ]);
Disable all permissions:
$mf->setPermissions([]);
Recommended Use Cases
This library is suitable for:
- Internal document automation systems
- Batch PDF consolidation workflows
- Compliance document generation
- Office document archival pipelines
- Backend administrative systems
- Legacy PHP applications requiring PDF normalization
Notes
This project prioritizes compatibility and operational reliability over minimal external dependencies.
If your workflow involves handling PDFs from unpredictable external sources, Ghostscript preprocessing significantly improves merge stability and interoperability across different PDF generators.
virdiggg/merge-files 适用场景与选型建议
virdiggg/merge-files 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 virdiggg/merge-files 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 virdiggg/merge-files 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 74
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-13