Example #1
0
def create_zugferd_pdf(docname,
                       verify=True,
                       format=None,
                       doc=None,
                       doctype="Sales Invoice",
                       no_letterhead=0):
    try:
        html = frappe.get_print(doctype,
                                docname,
                                format,
                                doc=doc,
                                no_letterhead=no_letterhead)
        pdf = get_pdf(html)
        xml = create_zugferd_xml(docname)

        if xml:
            facturx_pdf = generate_facturx_from_binary(
                pdf, xml.encode('utf-8')
            )  ## Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
            return facturx_pdf
        else:
            # failed to generate xml, fallback
            return get_pdf(html)
    except Exception as err:
        frappe.log_error(
            "Unable to create zugferdPDF for {2}: {0}\n{1}".format(
                err, xml, docname), "ZUGFeRD")
        # fallback to normal pdf
        return get_pdf(html)
Example #2
0
 def regular_pdf_invoice_to_facturx_invoice(self, pdf_content):
     self.ensure_one()
     assert pdf_content, 'Missing pdf_content'
     if self.type in ('out_invoice', 'out_refund'):
         facturx_xml_str, level = self.generate_facturx_xml()
         pdf_metadata = self._prepare_pdf_metadata()
         # Generate a new PDF with XML file as attachment
         pdf_content = generate_facturx_from_binary(
             pdf_content[0], facturx_xml_str, check_xsd=False,
             facturx_level=level, pdf_metadata=pdf_metadata)
         logger.info('%s file added to PDF invoice', FACTURX_FILENAME)
     return pdf_content
Example #3
0
def create_pdf():
    doctype = "Sales Invoice"
    name = "ACC-SINV-2020-00001"
    format = None
    doc = None
    no_letterhead = 0
    html = frappe.get_print(doctype,
                            name,
                            format,
                            doc=doc,
                            no_letterhead=no_letterhead)

    pdf = get_pdf(html)
    xml = create_zugferd_xml(name)

    facturxPDF = generate_facturx_from_binary(pdf, xml)
    newFile = open("filename.pdf", "wb")
    newFile.write(facturxPDF)

    return