question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot get to set Headers or Footers using pdfcallback function

See original GitHub issue

Hi, I am using the following code but can’t seem to get the header or footer in the pdf, can anybody suggest plz what am i doing wrong? Thanks in advance,

function pdfCallback(pdfObject) {
   var number_of_pages = pdfObject.internal.getNumberOfPages()
    var pdf_pages = pdfObject.internal.pages
    var myFooter = "Footer info"
    for (var i = 1; i < pdf_pages.length; i++) {
        // We are telling our pdfObject that we are now working on this page
        pdfObject.setPage(i)
        // The 10,200 value is only for A4 landscape. You need to define your own for other page sizes
        pdfObject.text(myFooter, .1, .2)
        pdfObject.text("my header text", .1, .1);
    } }
function generatepdf(){ document.getElementById('preview').classList.add('hide');
var element = document.getElementById('element-to-print');
html2pdf(element, {
  margin:       .1,
  filename:     'Interview_Form.pdf',
  image:        { type: 'jpeg', quality: 0.98 },
  html2canvas:  { dpi: 192 },
  jsPDF:        { unit: 'in', format: 'A4', orientation: 'portrait', footer: 'a' },
  pdfCallback: pdfCallback
});
document.getElementById('preview').classList.add('show');
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Jigisha-sublimecommented, Nov 19, 2020

@eKoopmans From all the examples it’s clear that we can add normal text to the pdf (i.e. page number) but, is there any way we can provide the dynamic header content in the pdf. For example, I want to repeat some specifically designed HTML headers and logo as a header on each page of the pdf so, is there any workaround for this? Please help if we have any solutions for this. because most of the libraries are failing to do that on the client-side.

1reaction
eKoopmanscommented, Jan 19, 2019

Hi, the v0.9.0 API added ways to add extra content to the PDF (including header/footer) - see here for an example with page numbers.

Closing as resolved!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alter the default header/footer when printing to PDF
It is possible to create custom headers and footer by using <header> and <footer> tags. I use this for generating PDF's using Chrome ......
Read more >
Add headers, footers, and Bates numbering to PDFs
Follow these steps to add headers, footers, and Bates numbering to PDFs using Acrobat. They can include a date, page numbers, title, author, ......
Read more >
How to avoid "header already sent" warning when loading a pdf
I use a custom module which implement a page callback function, and inside I use dompdf library. The pdf is displayed normally, but...
Read more >
API Reference Documentation - DocRaptor HTML to PDF ...
The HTML or XML that DocRaptor should use to create the document. Excel files should be XML while PDFs can be converted from...
Read more >
Unable to get PDF header & footer to show
I think you should save resouce file as .css file and load that , I was with this issue when I were not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found