HTML to PDF conversion might seem like a regular task, but it can be difficult to implement and maintain making your project much more complex. Thus, many nowadays solutions come from a 3rd party rigid and robust service providers. We are going to use a simple API call to take care of the conversion.
Let's begin by installing a ConvertAPI PHP Client:
composer require convertapi/convertapi-php
Note: if you don't want to use Composer, please follow the manual installation guide.
Once you have the library installed, simply run this code snippet:
ConvertApi::setApiSecret('your-api-secret'); $result = ConvertApi::convert('pdf', [ 'File' => '/path/to/my_file.html', ], 'html' ); $result->saveFiles('/path/to/result/dir');
That's it, just replace your secret and path to your file and it should work straight away.