Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

PDF printing with template

Security covered Under active development 76 sites

This module enables the generation of PDF files for printing based on a template. It allows you to import pages from existing PDF documents and insert view content, custom text, images, or HTML onto specified positions within the template.

This module uses library FPDI Generate a PDF file for printing based on a template.
You can import pages from existing PDF documents.

How to use:

  1. install module fpdi_print with composer require drupal/fpdi_print. It'll add libraries tcpdf & fpdi to vendor
  2. Create view page node with contextual filter (nid)
  3. Add Pdf Print (global) to Header or Footer Views page
    • Fill all the configuration
    • Path to pdf source file - version 1.4. /!\ Check your version pdf before upload, it doesn't work with version 1.5 or 1.6 Path asbolute /var/www/drupal/sites/default/files/template.pdf or relative sites/default/files/template.pdf
    • Add position x,y, text (format array yaml) /!\check validation yaml or /fpdi-print/validate before paste

If you leave the position configuration empty. It'll print contents of the view. You can set pdf header footer with global area custom text from views header footer
Example:

If your fpdf is Form filling and compatible (FPDM)
you can set configuration like this (you don't need position x,y)

- form: "address"
  text: "My city"
- form: "address"
  text: "My phone number"

You can goto page /fpdi-print/validate to check pdf and yaml format

for developper

There is hook fpdi_print_views for alter data positions before generate.
you can call service fpdi_print.print_builder
Format of positions : page number => [ x , y , (text|html|image), height , width]
the page number must start with 1 (NOT BEGIN WITH 0)

/*
$positions = [
 '1' => [
     [ 'x'=> 10, 'y'=>20, 'text'=>'Show text in page 1'],
     [ 'x'=> 15, 'y'=>40, 'height'=>50 , 'width'=>50, 'image'=>101 //you can add fid for image],
     [ 'x'=> 15, 'y'=>50,  'image'=>'/path/to/image' // add image path],
     [ 'x'=> 15, 'y'=>60,  'image'=>'<img src="/path/to/image1.png"/> <img src="/path/to/image2.jpg"/>'// add html multi images],
],
 '2' => [
     [ 'x'=> 10, 'y'=>20, 'height'=> 10, 'html'=>'Show <b>html</b>\n in page 2' ],
]
 '3' => [
     [ 'pdf'=>'/path/to/merge/file.pdf' ],
]
]
*/

    $pdf = \Drupal::service('fpdi_print.print_builder')->getPDF($positions, $filePdfTemplate);

//you can save pdf to file with $pdf->Output('I','yourFileName.pdf');
//or show in directly to browser 
    $response = new StreamedResponse();
    return $response->setCallback(function () use ($pdf) {
      ob_clean();
      $handle = fopen('php://output', 'w+');
      $pdf->Output();
      fclose($handle);
    });

Hook avaible before render pdf


/**
 * Implements hook_fpdi_print_views_alter().
 */
function myModule_fpdi_print_views_alter($dataPositions, $view, $filePdfTemplate){
  $view_id = $view->id();
...
}

Do you like this module? Show your appreciation by buying me ☕.

Drupal 9–11

Ask your assistant about PDF printing with template

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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.

Activity

Tracked releases
8
Tracked since
Jun 2024
Latest release
3 months ago
Releases (12 mo)
5 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.1.19 Stable 9–11 Jul 24, 2026
1.1.18 Stable 9–11 Jul 4, 2026
1.1.7 Stable 9–11 Apr 24, 2026
1.1.6 Stable 9–11 Apr 24, 2026
1.1.5 Stable 9–11 Apr 24, 2026
1.1.4 Stable 9–11 Jul 7, 2024
1.1.3 Stable 9–11 Jul 7, 2024
1.1.2 Stable 9–11 Jun 23, 2024