当前位置: 首页>>代码示例>>Python>>正文


Python pisa.CreatePDF方法代码示例

本文整理汇总了Python中xhtml2pdf.pisa.CreatePDF方法的典型用法代码示例。如果您正苦于以下问题:Python pisa.CreatePDF方法的具体用法?Python pisa.CreatePDF怎么用?Python pisa.CreatePDF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xhtml2pdf.pisa的用法示例。


在下文中一共展示了pisa.CreatePDF方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convertHtmlToPdf

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def convertHtmlToPdf(self,sourceHtml, outputFilename):
        """
         Open output file for writing (truncated binary) and
         converts HTML code into pdf file format

        :param sourceHtml: The html source to be converted to pdf
        :param outputFilename: Name of the output file as pdf
        :return: Error if pdf not generated successfully
        """
        resultFile = open(outputFilename, "w+b")

        # convert HTML to PDF
        pisaStatus = pisa.CreatePDF(sourceHtml, dest=resultFile)

        # close output file
        resultFile.close()

        # return True on success and False on errors
        return pisaStatus.err 
开发者ID:AnimeshShaw,项目名称:GeeksForGeeks-Content-Extractor,代码行数:21,代码来源:G4GExtractor.py

示例2: download_cv_pdf

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response 
开发者ID:PacktPublishing,项目名称:Django-2-Web-Development-Cookbook-Third-Edition,代码行数:18,代码来源:views.py

示例3: serve_pdf

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def serve_pdf(invoice, request):
    # Convert HTML URIs to absolute system paths so xhtml2pdf can access those resources

    def link_callback(uri, rel):
        # use short variable names
        sUrl = settings.STATIC_URL      # Typically /static/
        sRoot = settings.STATIC_ROOT    # Typically /home/userX/project_static/
        mUrl = settings.MEDIA_URL       # Typically /static/media/
        mRoot = settings.MEDIA_ROOT     # Typically /home/userX/project_static/media/

        # convert URIs to absolute system paths
        if uri.startswith(mUrl):
            path = os.path.join(mRoot, uri.replace(mUrl, ""))
        elif uri.startswith(sUrl):
            path = os.path.join(sRoot, uri.replace(sUrl, ""))

        # make sure that file exists
        if not os.path.isfile(path):
                raise Exception(
                        'media URI must start with %s or %s' % \
                        (sUrl, mUrl))
        return path

    # Render html content through html template with context
    template = get_template(settings.PDF_TEMPLATE)
    html = template.render(Context(invoice))

    # Write PDF to file
    # file = open(os.path.join(settings.MEDIA_ROOT, 'Invoice #' + str(id) + '.pdf'), "w+b")
    file = StringIO.StringIO()
    pisaStatus = pisa.CreatePDF(html, dest=file, link_callback=link_callback)

    # Return PDF document through a Django HTTP response
    file.seek(0)
    # pdf = file.read()
    # file.close()            # Don't forget to close the file handle
    return HttpResponse(file, content_type='application/pdf') 
开发者ID:SableWalnut,项目名称:wagtailinvoices,代码行数:39,代码来源:editor.py

示例4: pdf_workup

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def pdf_workup(request, pk):

    wu = get_object_or_404(models.Workup, pk=pk)
    active_provider_type = get_object_or_404(ProviderType,
                                             pk=request.session['clintype_pk'])

    if active_provider_type.staff_view:
        data = {'workup': wu}

        template = get_template('workup/workup_body.html')
        html  = template.render(data)

        file = TemporaryFile(mode="w+b")
        pisa.CreatePDF(html.encode('utf-8'), dest=file,
                encoding='utf-8')

        file.seek(0)
        pdf = file.read()
        file.close()

        initials = ''.join(name[0].upper() for name in wu.patient.name(reverse=False, middle_short=False).split())
        formatdate = '.'.join([str(wu.clinic_day.clinic_date.month).zfill(2), str(wu.clinic_day.clinic_date.day).zfill(2), str(wu.clinic_day.clinic_date.year)])
        filename = ''.join([initials, ' (', formatdate, ')'])

        response = HttpResponse(pdf, 'application/pdf')
        response["Content-Disposition"] = "attachment; filename=%s.pdf" % (filename,)
        return response

    else:
        return HttpResponseRedirect(reverse('workup',
                                            args=(wu.id,))) 
开发者ID:SaturdayNeighborhoodHealthClinic,项目名称:osler,代码行数:33,代码来源:views.py

示例5: renderInvoiceToPdf

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def renderInvoiceToPdf(invoice, user):
    """
    Renders a nice PDF display for the given invoice.
    """
    sourceHtml = renderInvoiceToHtml(invoice, user)
    output = io.StringIO()
    pisaStatus = pisa.CreatePDF(sourceHtml, dest=output)
    if pisaStatus.err:
        return None

    value = output.getvalue()
    output.close()
    return value 
开发者ID:quay,项目名称:quay,代码行数:15,代码来源:invoice.py

示例6: WritePDF

# 需要导入模块: from xhtml2pdf import pisa [as 别名]
# 或者: from xhtml2pdf.pisa import CreatePDF [as 别名]
def WritePDF(outFile, retValue):
		html_str = "" 
		for index in range(0, len(retValue), 2):
			html_str += textwrap.dedent("<ul> <li>{name} : <ul>output : {repr_val}</ul> </li> </ul>").format(name=retValue[index],repr_val=repr(retValue[index+1]))
		pisa.CreatePDF(cStringIO.StringIO(html_str), open(outFile, 'wb')) 
开发者ID:sadboyzvone,项目名称:passthief,代码行数:7,代码来源:core.py


注:本文中的xhtml2pdf.pisa.CreatePDF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。