Use custom paper size

Created on 1 October 2019, about 5 years ago
Updated 25 January 2023, almost 2 years ago

Hi!

I would like to use custom paper size with dompdf engine, but I don't know how I can do that. Can you show me some examples?

💬 Support request
Status

Active

Version

2.1

Component

Code

Created by

🇭🇺Hungary asrob Hungary 🇭🇺 🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands sorson

    I try to get a custom size paper working with Wkhtmltopdf. I created a new event Subscriber, but it doesn't work because --page-width and --page-height options are not supported, and only setting the paper size using the default_paper_size option is supported.

    The subscriber works with:

    $update_config = [
     'default_paper_size' => 'A4',
    ];

    But not with:

    $update_config = [
      'page_width' => '2.5in',
      'page_height' => '3.5in',
    ];

    Any direction how I can define a custom paper size with Wkhtmltopdf?

  • 🇳🇱Netherlands sorson

    I got a quick hard coded solution working.

    In /modules/contrib/entity_print/src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php:

        $this->pdf = new Pdf([
          'binary' => $this->configuration['binary_location'],
          'orientation' => $this->configuration['default_paper_orientation'],
          'username' => $this->configuration['username'],
          'password' => $this->configuration['password'],
          'page-size' => $this->configuration['default_paper_size'],
          'zoom' => $this->configuration['zoom'],
          'viewport-size' => $this->configuration['viewport_size'],
          'page-width' => '2in',
          'page-height' => '2in',
        ]);
    

    This could be implemented as a nice feature to the module. I will try to create a patch to propose to merge it, if I can find some time.

Production build 0.71.5 2024