Package Laravel untuk melakukan penggantian kata pada file menggunakan template dokumen (.rtf) yang sudah disediakan.
Laravel Package to perform word replacement on files using document templates (.rtf
) that have been provided., (*2)
[ID] Package Laravel untuk melakukan penggantian kata pada file menggunakan template dokumen (.rtf
) yang sudah disediakan., (*3)
, (*4)
From your projects root folder in terminal run:, (*5)
composer require novay/laravel-word-template
Register the package, (*6)
Laravel 5.5 and up
Uses package auto discovery feature, no need to edit the config/app.php
file., (*7)
Laravel 5.4 and below
Register the package with laravel in config/app.php
under providers
and aliases
with the following:, (*8)
'providers' => [ ... Novay\WordTemplate\WordTemplateServiceProvider::class, ]; 'aliases' => [ ... 'WordTemplate' => Novay\WordTemplate\Facade::class, ];
Siapkan template yang ingin Anda gunakan, pastikan template berupa file dokumen. Sebagai contoh anda bisa menggunakan contoh ini.
Jika tidak langsung terunduh secara otomatis, kamu bisa tekan Ctrl+S
untuk menyimpan secara manual dengan format .rtf
. Setelah terdownload cukup letakkan file tersebut di folder public
atau dimanapun anda mau., (*9)
Silahkan bermain-main dengan facade
ini:, (*10)
WordTemplate::export('file.rtf', array(), 'nama_file.doc');
Method ini membutuhkan 3 parameter didalam penggunaannya:, (*11)
Contoh: public_path('template/document.rtf')
Contoh. file.doc
Contoh
Agar cepat, salin baris berikut ke dalam file routes.php
Anda :Route::get('/', function () { $file = public_path('surat_pernyataan.rtf'); $array = array( '[NOMOR_SURAT]' => '015/BT/SK/V/2017', '[PERUSAHAAN]' => 'CV. Borneo Teknomedia', '[NAMA]' => 'Melani Malik', '[NIP]' => '6472065508XXXX', '[ALAMAT]' => 'Jl. Manunggal Gg. 8 Loa Bakung, Samarinda', '[PERMOHONAN]' => 'Permohonan pengurusan pembuatan NPWP', '[KOTA]' => 'Samarinda', '[DIRECTOR]' => 'Noviyanto Rahmadi', '[TANGGAL]' => date('d F Y'), ); $nama_file = 'surat-keterangan-kerja.doc'; return WordTemplate::export($file, $array, $nama_file); });
You need to prepare the template document that you want, for example you can download this file.
If it is not downloading automatically, you can just press Ctrl+S
to save it manually as .rtf
file., (*12)
You can use this facade
to play with this :, (*13)
WordTemplate('file.rtf', array(), 'nama_file.doc');
This method needs you to specify 3 parameters in it:, (*14)
Ex. public_path('template/document.rtf')
Ex. file.doc
Example
Copy this file in your routes directly for the instance :Route::get('/', function () { $file = public_path('surat_pernyataan.rtf'); $array = array( '[NOMOR_SURAT]' => '015/BT/SK/V/2017', '[PERUSAHAAN]' => 'CV. Borneo Teknomedia', '[NAMA]' => 'Melani Malik', '[NIP]' => '6472065508XXXX', '[ALAMAT]' => 'Jl. Manunggal Gg. 8 Loa Bakung, Samarinda', '[PERMOHONAN]' => 'Permohonan pengurusan pembuatan NPWP', '[KOTA]' => 'Samarinda', '[DIRECTOR]' => 'Noviyanto Rahmadi', '[TANGGAL]' => date('d F Y'), ); $nama_file = 'surat-keterangan-kerja.doc'; return WordTemplate::export($file, $array, $nama_file); });
Laravel Word Template is licensed under the MIT license. Enjoy!, (*15)