Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 分配错误:模块';reportlab.pdfgen.canvas';没有属性';acroform';_Python_Django_Pdf_Reportlab - Fatal编程技术网

Python 分配错误:模块';reportlab.pdfgen.canvas';没有属性';acroform';

Python 分配错误:模块';reportlab.pdfgen.canvas';没有属性';acroform';,python,django,pdf,reportlab,Python,Django,Pdf,Reportlab,我想使用reportLab在Django中的PDF上创建一个acroform。我已经为reportLab安装了软件包。 但在实现acroform时,im在AttributeError中获取:模块“reportlab.pdfgen.canvas”没有属性“acroform” from django.shortcuts import render from django.http import HttpResponse from io import BytesIO from reportlab.p

我想使用reportLab在Django中的PDF上创建一个acroform。我已经为reportLab安装了软件包。 但在实现acroform时,im在AttributeError中获取
:模块“reportlab.pdfgen.canvas”没有属性“acroform”

from django.shortcuts import render
from django.http import HttpResponse

from io import BytesIO
from reportlab.pdfgen import canvas
from django.http import HttpResponse

def index(request):
    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'

    buffer = BytesIO()

    # Create the PDF object, using the BytesIO object as its "file."
    p = canvas.Canvas(buffer)

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of functionality.
    p.drawString(100, 100, "Hello world.")
    canvas.acroform.checkbox(name='CB0',tooltip='Field CB0',checked=True,x=72,y=72+4*36,buttonStyle='diamond',borderStyle='bevelled',borderWidth=2,borderColor=red,fillColor=green,textColor=blue,forceBorder=True)

    # Close the PDF object cleanly.
    p.showPage()
    p.save()

    # Get the value of the BytesIO buffer and write it to the response.
    pdf = buffer.getvalue()
    buffer.close()
    response.write(pdf)
    return  response
我想创建一个PDF,如下所示 使用

p.acroForm.checkbox(..)
而不是

canvas.acroform.checkbox(..)
注意“acroForm”中的小写字母。

他们的文档错误:(第59页)