Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This project is not covered by Drupal’s security advisory policy.
This module integrates Drupal with Go-WkhtmltoX.
Installation
Install as usual, see Installing Drupal 8 Modules or Installing modules' Composer dependencies for further information.
Configuration
Add your endpoint to your settings.php
$config['go_wkhtmltox.settings']['endpoint'] = 'http://wkhtmltox:8080';
PDF example
use Drupal\go_wkhtmltox\API\Converter\ToPdfConverter;
use Drupal\go_wkhtmltox\API\Fetcher\DataFetcher;
$pdf = [
'#type' => 'inline_template',
'#template' => '<h1>Hello world!</h1>',
];
$pdf_data = (string) \Drupal::service('renderer')->renderPlain($pdf);
$converter = new ToPdfConverter();
$converter->setOption('extend', [
'dpi' => '300',
'image-dpi' => '300',
'image-quality' => '100',
'page-width' => '210mm',
'page-height' => '297mm',
]);
$fetcher = new DataFetcher();
$fetcher->setParam('data', $pdf_data);
$pdf_file = \Drupal::service('go_wkhtmltox.client')->convert($converter, $fetcher);
Image example
use Drupal\go_wkhtmltox\API\Converter\ToImageConverter;
use Drupal\go_wkhtmltox\API\Fetcher\DataFetcher;
$pdf = [
'#type' => 'inline_template',
'#template' => '<h1>Hello world!</h1>',
];
$pdf_data = (string) \Drupal::service('renderer')->renderPlain($pdf);
$converter = new ToImageConverter();
$converter->setOption('format', 'png');
// Sets the minimum value, it'll be auto-calculated.
$converter->setOption('width', 0);
$converter->setOption('extend', [
'transparent' => '--transparent',
// This option isn't added by itself.
// @see https://github.com/gogap/go-wkhtmltox/issues/8
'quality' => '0',
]);
$fetcher = new DataFetcher();
$fetcher->setParam('data', $pdf_data);
$pdf_file = \Drupal::service('go_wkhtmltox.client')->convert($converter, $fetcher);
Sponsors
Supporting organizations:
Project information
- Module categories: Developer Tools
- 1 site reports using this module
- Created by facine on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.