Skip to content

Commit

Permalink
fix: Disappearing letterhead header in pdf
Browse files Browse the repository at this point in the history
- fix: Make sure 'header-html' is extracted from document after it is rendered as html and loaded in wkhtmltopdf options, else it goes missing

(cherry picked from commit fc0ba51)
  • Loading branch information
marination authored and mergify[bot] committed Feb 1, 2024
1 parent 45e2683 commit e932958
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions frappe/utils/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def read_options_from_html(html):
return str(soup), options


def prepare_header_footer(soup):
def prepare_header_footer(soup: BeautifulSoup):
options = {}

head = soup.find("head").contents
Expand All @@ -240,10 +240,6 @@ def prepare_header_footer(soup):
for html_id in ("header-html", "footer-html"):
content = soup.find(id=html_id)
if content:
# there could be multiple instances of header-html/footer-html
for tag in soup.find_all(id=html_id):
tag.extract()

toggle_visible_pdf(content)
id_map = {"header-html": "pdf_header_html", "footer-html": "pdf_footer_html"}
hook_func = frappe.get_hooks(id_map.get(html_id))
Expand All @@ -256,6 +252,10 @@ def prepare_header_footer(soup):
css=css,
)

# there could be multiple instances of header-html/footer-html
for tag in soup.find_all(id=html_id):
tag.extract()

# create temp file
fname = os.path.join("/tmp", f"frappe-pdf-{frappe.generate_hash()}.html")
with open(fname, "wb") as f:
Expand Down

0 comments on commit e932958

Please sign in to comment.