xhtml2pdf does not detect div width
Asked Answered
M

0

7

I am using xhtml2pdf for converting html to pdf.

For some reason it does not detect the width of any div. I have tried giving width using style it still does not work. What am I do doing wrong?

    <html>
<head>

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

</html>

In the above code the div does not have a width of 100px or 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("\\","/")
Mckelvey answered 21/10, 2013 at 6:18 Comment(6)
I'm running into the same issue; did you ever find a work around?Leucopoiesis
No I have not. But it detects table column width and I have used table everywhere instead of div.Mckelvey
What about height? Can't apply height to any elementYounglove
You can explicitly add height and width to every element. You have add it specifically to each element.Mckelvey
What do you mean adding width and height specifically to each element? How can I do so?Chalcocite
Specifically means inline.Mckelvey

© 2022 - 2024 — McMap. All rights reserved.