定制 jhon/word_replacer_wrapper 二次开发

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

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

jhon/word_replacer_wrapper

Composer 安装命令:

composer require jhon/word_replacer_wrapper

包简介

realiza reemplazo de palabras en plantillas de word y realiza la conversion del archivo final a extensiones requeridas como pdf

关键字:

README 文档

README

replace words on .docx files and convert to pdf

install with

composer require jhon/word_replacer_wrapper

Dependencies

You need to install LibreOffice.

Usage

You must include vendor/autoload.php

require __DIR__ . '/vendor/autoload.php';

Class namespace

use Jsvptf\WordReplacerWrapper\WordReplacerWrapper;

Default configuration

//template to process
$template = 'templateDirectory/test.docx';

Define data to convert

//array of ITypeTableChild elements
$tableData = [
        [
            new Text('a'),
            new Text('b'),
        ],
        [
            new Text('d'),
            new Table($nestedTableData),
        ]
];

//default configuration, array of IType elements
 
$data = [
    'field1' => new Text('xxxxxxxxxxx'),
    'field2' => new Table($tableData),
    'field3' => new Image('./images/test.png', 80, 80),
    'field4' => new Pagination('Page {PAGE} of {NUMPAGES}.'),
    'styleText' => new Text('some with style', [
        'size' => 20,
        'bold' => true,
        'name' => 'Courier New'
    ])
];

//folder for create files
$temporalDirectory = 'testOne';

$WordReplacerWrapper = new WordReplacerWrapper(
    'templateDirectory/test.docx', //docx template
    $data, //data to replace
    'prueba1', //destination folder
    'libreoffice' //libreoffice binary
);

//execute replace and convert to pdf
$routes = $WordReplacerWrapper->replaceData();

//routes
["template"]=>
  string(17) "testOne/test.docx"
["document"]=>
  string(26) "testOne/document_test.docx"
["pdf"]=>
  string(25) "testOne/document_test.pdf"

Dinamic configuration

//if you want to know the required variables you can use  
$fields = $WordReplacerWrapper->getRequiredFields()

//$fields
array(7) {
  [0]=>
  string(6) "field1"
  [1]=>
  string(6) "field3"
  [5]=>
  string(6) "header"
  [6]=>
  string(6) "footer"
}

$WordReplacerWrapper->setData(['field1' => new Text('sebastian')]);
$WordReplacerWrapper->setTemporalDir('testTwo');
$routes = $WordReplacerWrapper->replaceData();

//routes
["template"]=>
  string(17) "testTwo/test.docx"
["document"]=>
  string(26) "testTwo/document_test.docx"
["pdf"]=>
  string(25) "testTwo/document_test.pdf"

Header and footer

you must add header and footer key to data, implementing a Jsvptf\WordReplacerWrapper\types\Table class and the template file MUST has content on header and footer space, you can see it on example/convertDocx.php

$data = [
    'header' => new Table($tableData),
    'footer' => new Table($tableData)
    ...
];

You can find the complete example on example directory

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固