jean-humann / docs-to-pdf

Generate PDF for document website 🧑‍🔧
https://www.npmjs.com/package/docs-to-pdf
MIT License
104 stars 18 forks source link

how to inject vars into html template #199

Closed gregpalaci closed 1 year ago

gregpalaci commented 1 year ago

as per https://pptr.dev/api/puppeteer.pdfoptions/#properties how do you pass



- date formatted print date

- title document title

- url document location

- pageNumber current page number

- totalPages total pages in the document```
to
--headerTemplate

is it `--headerTemplate="${date}"` etc
codingluke commented 1 year ago

The information is injected through css classes so you have to add html tags with the corresponding css classes. Here an example of mine.

  footerTemplate: `
    <style>
      .footer {
        height: 15px; 
        width: 100%; 
        display: flex; 
        justify-content: space-between; 
        align-items: flex-end;
        font-size: 8px; 
        margin: 10px 55px;
        font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, BlinkMacSystemFont;
        border-top: 1px solid rgba(0,0,0,0.05);
      }
    </style>
    <div class="footer">
      <div></div>
      <div><span class="pageNumber"></span> / <span class="totalPages"></span></div>
    </div> `,
jean-humann commented 1 year ago

Resolved by @codingluke

gregpalaci commented 1 year ago

Thanks! perfect; at some point maybe an example in the docs for others?