PHP Reports Documentation

PHP-Reports is a cloud based, interactive report engine which helps in generating well formatted PDF reports from Word / DOCX templates in PHP, ASP.NET, ASP.NET MVC, WPF, Silverlight, WinRT, HTML5, Windows Forms, Java, Python, Objective-C, Swift, Delphi and other languages as well.

1. Getting API Key

Create free account at https://www.php-reports.com and get your free API Key.

2. Creating Your First Template

To accelerate the process of creating your reports and applications, PHP Reports takes advantage of Microsoft Word's design capabilites. Simply create a Microsoft Word file and design your report.

3. Using Template Variables

You can use template variables in your Word template. Tamplate variables take their name from the contents of their double curly braces and they can later be replaced with a concrete value.

All template variable names within a template string must be unique. Template variable names are case-insensitive.

4. Upload Your Template

Save and upload your teamplte at "Template Manager" section in https://www.php-reports.com

5. Include PHPReports.php Class to Your Project

Download https://github.com/murat-cileli/php-reports or install via Composer.

composer require murat-cileli/php-reports

6. Generating Reports

Create a PHPReports object with your API Key.

$pr = new PHPReports('f9nb3k8bzfumne6g6yu6fu4d');

Set uploaded template ID

$pr->setTemplateId(2);

Set output file type. Default output type is PDF. You can pass PHPReports::OUTPUT_DOCX instead.

$pr->setOutputFileType(PHPReports::OUTPUT_PDF);

Get download URL of report in JSON. You can pass PHPReports::ACTION_FORCE_DOWNLOAD to direct download generated report.

$pr->setOutputAction(PHPReports::ACTION_GET_DOWNLOAD_URL);

Set output file name.

$pr->setOutputFileName('My_Generated_Report.pdf');

Set template variables. You can assign a single value or an array to template variables

$pr->setTemplateVariables(
array(
  'client_name' => 'Murat Cileli',
  'address' => 'Kadikoy, Istanbul / Turkey',
  'address' => 'Kadikoy, Istanbul / Turkey',
  'date' => '10.12.2016',
  'phone' => '0090 339 9 22',
  'email' => 'murat.cileli@gmail.com',
  'notes' => 'Thank you for your purchase.',
  'quantities' => array('6', '3', '4'),
  'products' => array('Apple iPhone 5S', 'Samsung Galaxy S5', 'Office 365 License'),
  'prices' => array('490 USD', '399 USD', '199 USD'),
));

Finally, generate your report using single line of code.

$pr->generateReport();

Your report will looks like:

Error Codes

{
  "result": "error",
  "error_code": 10,
  "error_message": "API Key is not defined"
}
{
  "result": "error",
  "error_code": 11,
  "error_message": "API Key is not valid"
}
{
  "result": "error",
  "error_code": 12,
  "error_message": "JSON is not valid"
}
{
  "result": "error",
  "error_code": 14,
  "error_message": "Template ID not found"
}
{
  "result": "error",
  "error_code": 15,
  "error_message": "Template file not found"
}
{
  "result": "error",
  "error_code": 17,
  "error_message": "Invalid MIME type"
}
{
  "result": "error",
  "error_code": 18,
  "error_message": "Can not read template file"
}
PHPDOCX Alternative