PHP Classes

File: tests/templates/sample_docx_structure.md

Recommend this page to a friend!
  Packages of MVONE AYORATOU ARTHUR   Document Generator X   tests/templates/sample_docx_structure.md   Download  
File: tests/templates/sample_docx_structure.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Document Generator X
Generate PDF documents from HTML or DOCX templates
Author: By
Last change:
Date: 3 days ago
Size: 2,390 bytes
 

Contents

Class file image Download

DOCX Template Structure Guide

Since DOCX files are binary, you need to create the template manually in Microsoft Word or LibreOffice.

How to Create a DOCX Template

  1. Open Microsoft Word or LibreOffice Writer
  2. Create a new document
  3. Add the following placeholders (copy exactly as shown):

Template Content (Copy this into your Word document)

{{company_logo:image,width:400,ratio:16:9}}

===========================================
        DOCUMENT GENERATOR TEST
===========================================

TEXT VARIABLES
--------------
Full Name: {{full_name:text}}
Email: {{email:string}}
Description: {{description:text}}

NUMBER VARIABLES
----------------
Age: {{age:number}} years old
Quantity: {{quantity:integer}} items
Price: ${{price:int}}

DATE VARIABLE
-------------
Created Date: {{created_date:date}}

BOOLEAN VARIABLE
----------------
Is Active: {{is_active:boolean}}

-------------------------------------------
Generated by DocumentGeneratorX
Test completed successfully!

Variable Reference

| Placeholder | Type | Example Value | |------------|------|---------------| | {{company_logo:image,width:400,ratio:16:9}} | Image with ratio | URL or file path | | {{full_name:text}} | Text | "John Doe" | | {{email:string}} | String | "john@example.com" | | {{description:text}} | Text | "Lorem ipsum..." | | {{age:number}} | Number | 28 | | {{quantity:integer}} | Integer | 150 | | {{price:int}} | Integer | 99 | | {{created_date:date}} | Date | "2024-01-15" | | {{is_active:boolean}} | Boolean | true/false |

Save the Template

  1. Save the document as `sample.docx`
  2. Place it in your Laravel storage: `storage/templates/sample.docx`

Usage in Code

use Hp\Documentgeneratorx\Facades\DocumentGenerator;

$docxPath = DocumentGenerator::template(storage_path('templates/sample.docx'))
    ->variables([
        'company_logo' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/1280px-Google_Images_2015_logo.svg.png',
        'full_name' => 'John Doe',
        'email' => 'john@example.com',
        'description' => 'Test document generated with all variable types.',
        'age' => 28,
        'quantity' => 150,
        'price' => 99,
        'created_date' => now()->format('Y-m-d'),
        'is_active' => true,
    ])
    ->format('docx')
    ->generate();