PHP Document Generation Examples

Prerequisite Files

For some examples to work correctly, ensure the following files are present in the same directory as the PHP scripts:

HTML to PDF Conversion

Generate PDF

Converts the content of sample.html into a PDF document using the Dompdf library and streams it for download.

HTML to Word (.docx) Conversion

Generate Word Document

Populates a template.docx file with content extracted from sample.html using the PHPWord library. The generated .docx file is then streamed for download.

HTML to Excel (.xlsx) Conversion

From HTML Tables

Generate Excel (from HTML Tables)

Extracts tables from sample.html and converts each table into a separate sheet in an Excel .xlsx file using PhpSpreadsheet. The file is then streamed for download.

Simple Spreadsheet from PHP Data

Generate Excel (Simple Data)

Generates an Excel .xlsx file directly from PHP array data, including headers, formulas, and basic styling, using PhpSpreadsheet. The file is streamed for download.