diff --git a/frappe/__init__.py b/frappe/__init__.py index cf8e52c160..625e7aa7c9 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -11,6 +11,7 @@ be used to build database driven apps. Read the documentation: https://frappeframework.com/docs """ +import base64 import copy import functools import importlib @@ -1665,14 +1666,15 @@ def get_file_json(path): return json.load(f) -def read_file(path, raise_not_found=False): - """Open a file and return its content as Unicode.""" +def read_file(path, raise_not_found=False, as_base64=False): + """Open a file and return its content as Unicode or Base64 string.""" if isinstance(path, str): path = path.encode("utf-8") if os.path.exists(path): - with open(path) as f: - return as_unicode(f.read()) + with open(path, "rb" if as_base64 else "r") as f: + content = f.read() + return base64.b64encode(content).decode("utf-8") if as_base64 else as_unicode(content) elif raise_not_found: raise OSError(f"{path} Not Found") else: diff --git a/frappe/templates/print_formats/pdf_header_footer_chrome.html b/frappe/templates/print_formats/pdf_header_footer_chrome.html index 8916fad898..de7e6f8016 100644 --- a/frappe/templates/print_formats/pdf_header_footer_chrome.html +++ b/frappe/templates/print_formats/pdf_header_footer_chrome.html @@ -34,7 +34,7 @@ {{ tag | string }} {%- endfor %} -
+