Programmatically adding headers and footers



  • If I wanted to programatically add headers and footers for each child template - how would I go about doing that? Each child requires a unique header i.e. Section 1, Section 2, Section 3. Each footer would require a page number so there would be a continuous flow throughout the whole document.

         await reporter.documentStore.collection('templates').insert({
            content: pages.page1,
            engine: 'jsrender',
            recipe: 'html',
            name: 't1',
            chrome: {
              displayHeaderFooter: true,
              footerTemplate: `TEST FOOTER TEMPLATE`,
              margin: {
                top: "2cm",
                bottom: "3cm",
                right: "1cm",
                left: "1cm"
              }
            }
          })
    
          await reporter.documentStore.collection('templates').insert({
            content: pages.page2,
            engine: 'jsrender',
            recipe: 'html',
            name: 't2'
          })
    
          await reporter.documentStore.collection('templates').insert({
            content: 'xx',
            engine: 'jsrender',
            recipe: 'html',
            name: 't3'
          })
    
          const request = {
            template: { content: '{#child t1} {#child t2} {#child t3}', engine: 'none', recipe: 'chrome-pdf' }
          }
    

    Thanks



  • Perhaps, lets the first start with static generation and then do the dynamic part.

    Child templates are mostly producing HTML and have no impact on the pdf header or footer.
    https://jsreport.net/learn/child-templates
    However, you can add to the page some hidden marks through child templates and later produce headers/footer based on these values. This can be achieved using pdf utils extension
    https://jsreport.net/learn/pdf-utils
    This example mentioned in the docs could help
    https://playground.jsreport.net/w/admin/Wy6stA8t


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.