8 – Entity Print PDF Layout for Views page

My requirement is to convert a views page into a PDF. I have created the views page with table formatting and a PDF plugin attached to the header that allows one to download the views page as PDF. I created an entity-print.html twig template and an HTML structure copied from the answer in this post How to customize entity print pdf and created a twig variable ‘footer’ in THEME_preprocess_page function in the theme’s .theme file but the calls {{ footer }} to that variable in the template returns nothing.

In other to at least test CSS formatting, I placed these in the respective files:


    <meta charset="utf-8">
    <title>{{ title }}</title>
    {{ entity_print_css }}
{# The footer is repeated on all pages and must be printed first. #}

    {{  footer  }}
{%  if cover_page  %}
<div class="cover-page">
    {{ cover_page }}
{%  endif  %}
{# The header is repeated after the cover page for all pages. #}
    {{  header  }}
<div class="page">
    {{ content }}


function THEMENAME_preprocess_page(&$variables) {
  $variables('footer') = "HERE IS YOUR FOOTER";
  $variables('header') = "HERE IS YOUR HEADER";


   views_page_machine_name: 'medlaberp_gin/result-pdf'


      styles/result-pdf.css: {}

and then created result-pdf.css but the styles did not change anything in the generated pdf.

One of the answers in another post Entity print get variable in twig template pointed to creating an entity specific template for layout of the PDF with HTML as required. For example, for the article content type you have node–article–pdf.html.twig. What is the template suggestion for a views as described in my case?

The question is how do I achieve:

  1. create a HTML layout format that is fed all the fields from the views page
  2. rightly set the footer/header variable for output in the entity-print.html template mentioned above
  3. turn bullet into A pdf (so that the download link on the views page generates the formatted html as pdf).

Perhaps bullet 1-3 is irrelevant, a step by step direction on how to have a views page formatted as required and converted to PDF using the entity print module will be appreciated.