Cannot get to set Headers or Footers using pdfcallback function
See original GitHub issueHi, 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:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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!