Allow print to !pdf

This commit is contained in:
Tobias 2019-01-17 12:10:41 +13:00
parent f8cf1996a2
commit a5eb814c18

View file

@ -1146,13 +1146,12 @@ def badge(request, user_id, format="png"):
user_id = int(user_id)
user = User.objects.get(pk=user_id)
return render_badge(user, format='pdf')
return render_badge(user, format=format)
def _convert_img(img, outformat="png", dpi=600, width=None):
if hasattr(img, "encode"): #a string, or a SafeText
img=img.encode()
width = width or dpi*5.83 #5.83 inches in A5 portrait
conversion_cmdline = [
"convert",
@ -1164,7 +1163,6 @@ def _convert_img(img, outformat="png", dpi=600, width=None):
conversion_cmdline.extend(["-background","white",
"-flatten"])
conversion_cmdline.extend(["-", "{}:-".format(outformat)])
if outformat=="pdf":
# Inkscape results in nicer pdf render, embedding fonts etc where possible
conversion_cmdline = [
@ -1179,6 +1177,7 @@ def _convert_img(img, outformat="png", dpi=600, width=None):
def render_badge(user, format="png", overlay=False, request=None):
if request and waffle.flag_is_active(request, "force_badge_overlay"):
overlay=True
rendered = render_badge_svg(user, overlay=overlay)
if format == "png":
rendered = _convert_img(rendered, outformat="png")