Score:-2

PDF template page numbers

sg flag

I am currently trying to insert page numbers to generated PDFs. I tried the following solution with CSS counters, in the entity-pring.css file.

.page {
  padding: 20px;
}

.page img {
  max-width: 100%;
  height: auto;
}

.page td img {
  max-width: none;
}

@page {
  margin: 50px 25px 100px 25px;
}

#footer {
  position: fixed;
  bottom: -60px;
  left: 0px;
  right: 0px;
  background-color: #ffffff;
  height: 50px;
}

#footer .page:after {
  content: counter(page) " of " counter(pages);
}

In the entity-print.html.twig file, I use the following code.

<html>
  <head>
    <meta charset="utf-8">
      <title>{{ title }}</title>
      {{ entity_print_css }}
  </head>
  <body>
    <div class="page">
      {{ content }}
    </div>
    <div id="footer">
      <p class="page">Page </p>
    </div>
  </body>
</html>

This also works.

<img src="https://www.drupalcenter.de/files/Page Counter.png" alt="" />

The back part is still completely missing. Does anyone have any idea? I've already tried a few things, but I didn't find the right solution.

I got some inspiration from PDF Styling & Reference > Advanced Topics: Page Numbers.

Kevin avatar
in flag
`content: counter(page) " of " counter(pages);` this is valid CSS? Are those Drupal template variables? CSS won't know what those are. Anyway, you should know that HTML to PDF conversion is very limited. Stick to basic HTML and basic CSS for best compatibility.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.