You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue Description:
I am using the pdfkit library to convert HTML content to a PDF file with specified header and footer HTML. However, the header and footer are not showing up in the generated PDF.Also, it is not working when I pass HTML local paths in 'header-html' and 'footer-html' options.
Code Snippet:
importpdfkitdefconvert_html_to_pdf(html_content, output_pdf, header_html, footer_html):
options= {
'page-size': 'A4',
'no-images': '',
'margin-top': '15mm',
'margin-right': '15mm',
'margin-bottom': '15mm',
'margin-left': '15mm',
'header-html': header_html,
'footer-html': footer_html,
}
pdfkit.from_string(html_content, output_pdf, options=options)
if__name__=="__main__":
# Dummy HTML contenthtml_content=""" <!DOCTYPE html> <html> <head> <title>Sample HTML to PDF</title> </head> <body> <h1>Hello, this is the main content of the page!</h1> <p>This is a sample HTML content.</p> </body> </html> """# Dummy header HTML contentheader_html=""" <!DOCTYPE html> <html> <head> <title>Header</title> </head> <body> <header> <h2>This is the header of the page</h2> </header> </body> </html> """# Dummy footer HTML contentfooter_html=""" <!DOCTYPE html> <html> <head> <title>Footer</title> </head> <body> <footer> <p>This is the footer of the page</p> </footer> </body> </html> """# Output PDF fileoutput_pdf="output_file.pdf"# Convert HTML to PDFconvert_html_to_pdf(html_content, output_pdf, header_html, footer_html)
print(f"PDF generated: {output_pdf}")
The text was updated successfully, but these errors were encountered:
Hello, I'm facing the same issue when adding header elements to the generated PDF files. The simplest way I found was to add the header directly in the HTML and control it using the CSS @media property.
Issue Description:
I am using the
pdfkit
library to convert HTML content to a PDF file with specified header and footer HTML. However, the header and footer are not showing up in the generated PDF.Also, it is not working when I pass HTML local paths in 'header-html' and 'footer-html' options.Code Snippet:
The text was updated successfully, but these errors were encountered: