def generate_pdf(self, name, data): #template = '{}.html'.format(name) #template = get_template(template) html_content = data #template.render(data) pdf_content = render_pdf(html_content) return pdf_content
def generate_pdf(self, name, data): template = "{}.html".format(name) template = get_template(template) html_content = template.render(data) pdf_content = render_pdf(html_content) return pdf_content
def post(self, request, notice_of_application_to_vary_order_id): html = request.data['html'] json_data = request.data['json_data'] uid = request.user.id notice_of_application_to_vary_order = self.get_notice_of_application_to_vary_order_for_user( notice_of_application_to_vary_order_id, uid) if not notice_of_application_to_vary_order: return HttpResponseNotFound(no_record_found) name = request.query_params.get("name") pdf_type = request.query_params.get("pdf_type") version = request.query_params.get("version") if None in [name, pdf_type, version]: return HttpResponseBadRequest("Missing parameters.") try: pdf_result = self.get_pdf_by_notice_of_application_to_vary_order_id_and_type( notice_of_application_to_vary_order_id, pdf_type) pdf_content = render_pdf(html) (pdf_key_id, pdf_content_enc) = settings.ENCRYPTOR.encrypt(pdf_content) (pdf_key_id, json_enc) = settings.ENCRYPTOR.encrypt( json.dumps(json_data).encode("utf-8")) if pdf_result: pdf_result.data = pdf_content_enc pdf_result.json_data = json_enc pdf_result.key_id = pdf_key_id pdf_result.pdf_type = pdf_type pdf_result.version = version else: pdf_result = FormPdf( notice_of_application_to_vary_order= notice_of_application_to_vary_order, data=pdf_content_enc, json_data=json_enc, key_id=pdf_key_id, pdf_type=pdf_type, version=version, ) pdf_result.save() notice_of_application_to_vary_order.pdf_types = pdf_type notice_of_application_to_vary_order.save() except Exception as ex: LOGGER.error("ERROR: Pdf generation failed %s", ex) raise if request.query_params.get("noDownload"): return HttpResponse(status=204) else: return create_download_response(pdf_content)
def generate_pdf(self, name, data): pdf_content = render_pdf(data) return pdf_content
def generate_pdf(self, data): html_content = data pdf_content = render_pdf(html_content) return pdf_content