7

我正在使用 xhtml2pdf 将 html 转换为 pdf。

由于某种原因,它没有检测到任何 div 的宽度。我尝试使用样式给出宽度它仍然不起作用。我做错了什么?

    <html>
<head>

</head>
<body>
<style>
    div{
        width:100pt;
        height:100pt;
        border:Solid red 1pt;
    }
</style>
<div>
    WOw a pdf
</div>
</body>

</html>

在上面的代码中,div 的宽度不是 100px 或 100pt。

def myview(request):
    options1 = ReportPropertyOption.objects.all()
    for option in options1:
        option.exterior_images = ReportExteriorImages.objects.filter(report = option)  
        option.interior_images = ReportInteriorImages.objects.filter(report = option)
        option.floorplan_images = ReportFloorPlanImages.objects.filter(report = option)

    html  = render_to_string('report/export.html', { 'pagesize' : 'A4', }, context_instance=RequestContext(request,{'options1':options1}))
    result = StringIO.StringIO()

    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources )
    if not pdf.err:
        return HttpResponse(result.getvalue(), mimetype='application/pdf')
    return HttpResponse('Gremlins ate your pdf! %s' % cgi.escape(html))

def fetch_resources(uri, rel):  

    path = os.path.join(settings.MEDIA_ROOT, uri.replace("/media/", ""))

    return path.replace("\\","/")
4

0 回答 0