def download(type): if type == "pdf": main = page.to_latex() pdfl = PDFLaTeX.from_binarystring(main.encode("utf-8"), jobname="test") ret_file, _, _ = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=False) elif type == "json": ret_file = json.dumps(page.to_dict(), indent=4) elif type == "tex": ret_file = page.to_latex() return Response( ret_file, mimetype=f"text/{type}", headers={"Content-disposition": f"attachment; filename=mcv.{type}"}, )
def create_pdf(): text = request.get_json(force=True).get("text") print(text) print("_-----------------------_") name = "blub" encoding = "utf-8" raw_text = r'{}'.format(text) #print(raw_text) pdf, log, completed_process = PDFLaTeX.from_binarystring( raw_text.encode(encoding=encoding), name).create_pdf() #return send_file(base64.b64encode(pdf), mimetype="application/pdf") #print(bytearray(pdf).decode("utf-8")) #return base64.b64encode(pdf) # f = open("keks2.pdf", "wb") #print(base64.b64encode(pdf)) # f.write(base64.b64encode(pdf)) # f.close() return make_response(jsonify({"message":base64.b64encode(pdf).decode("ascii")}), 200) return send_file(pdf, mimetype="application/pdf", as_attachment=True, attachment_filename="blub.pdf") return make_response(jsonify({"message":str(base64.b64encode(bin(pdf)))}), 200)