fix: read_file return base64 encoded string
- added flag to read_file to return base64 encoded string - fixed pdf_header_footer_chrome to remove unused subst function call - added new_pdf_backend flag to get_print_format_template function
This commit is contained in:
parent
3caa2414e0
commit
cf0fe8eecd
3 changed files with 10 additions and 6 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
{{ tag | string }}
|
||||
{%- endfor %}
|
||||
</head>
|
||||
<body onload="subst()">
|
||||
<body>
|
||||
<div class="print-format">
|
||||
<div class="wrapper">
|
||||
{% for tag in content -%}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,9 @@ def get_rendered_template(
|
|||
|
||||
template = None
|
||||
if hook_func := frappe.get_hooks("get_print_format_template"):
|
||||
template = frappe.get_attr(hook_func[-1])(jenv=jenv, print_format=print_format)
|
||||
template = frappe.get_attr(hook_func[-1])(
|
||||
jenv=jenv, print_format=print_format, new_pdf_backend=new_pdf_backend
|
||||
)
|
||||
|
||||
if template:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue