Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Weasyprint only gives me empty pdfs when I'm trying to print newsarticles

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 25
    Answer it
    #!/usr/bin/python3.5 
    
    from weasyprint import HTML
    
    url = "http://ekstrabladet.dk/112/nye-oplysninger-i-30-aar-gammel-mordgaade/6579176"
    
    HTML(url).write_pdf("test.pd")

    The problem is that the final pdf has only part of the webpage.
    I'm assuming that this is due to the stylesheet not being part of it but how do i do that and also, is there a generic method of applying css rather than me having to apply the webpage specific stylesheet ?

     

 1 Answer(s)

  • Hi peterjnielsen.

    First you have to install reportlab in your system then follow the below code .

     pip install reportlab

    then you have to add python packages..
    
    import reportlab
    def pdf_view1(request1):
        f1 = FileSystemStorage1()
        filename = 'mypdf.pdf'
        if fs.exists(filename):
            with f1.open(filename) as pdf:
                response = HttpResponse(pdf, content_type='application1/pdf1')
                response['Content-Disposition'] = 'attachment; filename="mypdf.pdf1"'
                return response
        else:
            return HttpResponseNotFound('The requested pdf was not found in our server or can not find .')
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: