PDF Tools is a drupal module to make it easier to manipulate PDF files. It provides service definitions and interfaces
for PDF generation, manipulation, analysis and conversion. The default implementations of these services use local
command-line tools, contrib modules provide alternative implementations.
Generation
The pdf_tools.generator service handles the generation of PDF's from html content. The default implementation requires wkhtmltopdf is installed on the local machine. The pdf_tools_docker module provides an alternative implementation utilising the wkhtmltopdf container available on the docker network.
Example
// Convert an entity to a PDF file.
$generator = \Drupal::service('pdf_tools.generator');
$pdf_uri = $generator->entityToPDF($entity_load, 'view_mode', $options);
Alternatively we can convert a URL to a pdf.
// Convert an entity to a PDF file.
$generator = \Drupal::service('pdf_tools.generator');
$uri = $generator->generateFromUrl(
Url::fromRoute(
'entity.node.canonical',
[
'node' => 1,
],
[
'absolute' => TRUE,
]
)->toString(),
$options
);
Analysis
The pdf_tools.analyser service provides methods that extract information from PDF files. The default implementation
uses pdftk in the local command line.
Example
// Get the number of pages in the pdf document.
$analyser = \Drupal::service('pdf_tools.analyser');
$num_pages = $analyser->countPages('private://path/my.pdf');
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the PDF ecosystem
Most installed first
Activity
Release Timeline
Releases
| Version | Type | Core | Release date | |
|---|---|---|---|---|
| 2.0.0-alpha2 | Pre-release | May 15, 2023 | ||
| 2.0.0-alpha1 | Pre-release | May 15, 2023 | ||
| 2.x-dev | Dev | May 15, 2023 |