WeasyPrint | The awesome document factory | Document Editor library

 by   Kozea Python Version: 60.1 License: BSD-3-Clause

kandi X-RAY | WeasyPrint Summary

kandi X-RAY | WeasyPrint Summary

WeasyPrint is a Python library typically used in Editor, Document Editor applications. WeasyPrint has no vulnerabilities, it has a Permissive License and it has medium support. However WeasyPrint has 25 bugs and it build file is not available. You can install using 'pip install WeasyPrint' or download it from GitHub, PyPI.

The awesome document factory

            kandi-support Support

              WeasyPrint has a medium active ecosystem.
              It has 5852 star(s) with 602 fork(s). There are 137 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              There are 173 open issues and 1402 have been closed. On average issues are closed in 295 days. There are 6 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of WeasyPrint is 60.1

            kandi-Quality Quality

              WeasyPrint has 25 bugs (0 blocker, 0 critical, 21 major, 4 minor) and 278 code smells.

            kandi-Security Security

              WeasyPrint has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              WeasyPrint code analysis shows 0 unresolved vulnerabilities.
              There are 49 security hotspots that need review.

            kandi-License License

              WeasyPrint is licensed under the BSD-3-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              WeasyPrint releases are available to install and integrate.
              Deployable package is available in PyPI.
              WeasyPrint has no build file. You will be need to create the build yourself to build the component from source.
              WeasyPrint saves you 17354 person hours of effort in developing the same functionality from scratch.
              It has 34422 lines of code, 1442 functions and 105 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed WeasyPrint and discovered the below as its top functions. This is intended to give you an instant insight into WeasyPrint implemented functionality, and help decide if they suit your requirements.
            • Creates the flex layout for the specified box .
            • Creates a PDF file .
            • Creates a layout for a multi - column .
            • Find the style attributes in the given DOM tree .
            • Determines the preferred and column widths for the given table and preferred cells .
            • Create a path from SVG .
            • Splits the first line of the given text into the style .
            • Preprocess the stylesheet
            • draw a gradient
            • Split an inline box .
            Get all kandi verified functions for this library.

            WeasyPrint Key Features

            No Key Features are available at this moment for WeasyPrint.

            WeasyPrint Examples and Code Snippets

            Weasyprint failed to load image at url: Name or service not known
            Pythondot img1Lines of Code : 11dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from django.utils.six.moves.urllib.parse import urlsplit
            def test(request):
                scheme = urlsplit(request.build_absolute_uri(None))
                context = { 
                    'host_url': f"{scheme.scheme}://{scheme.netloc}"
                return render(request,
            Weasyprint failed to load image at url: Name or service not known
            Pythondot img2Lines of Code : 2dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            HTML(string=template_string, base_url=".", url_fetcher=url_fetcher).write_pdf(results)
            copy iconCopy
            @media print {
              .widget {
                break-inside: avoid;
                page-break-inside: avoid;
            Using Weasyprint to create file response
            Pythondot img4Lines of Code : 11dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import io
            def download_pdf(request, song_id):
                buffer = io.BytesIO()
                # ...
                chordsheet_html.write_pdf(buffer, stylesheets=[chordsheet_css])
                return FileResponse(buffer, as_attachment=True, filename=so
            Render image in template.html with Jinja2 and weasyprint in a PDF
            Pythondot img5Lines of Code : 10dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import os
            this_folder = os.path.dirname(os.path.abspath(__file__))
            template_vars = {"title" : "Something...",
                            "vulnerabilities_table": "hello world",
                             "image_path": 'file://' + os.p
            So can't use weasyprint what is the best thing to do?
            Pythondot img6Lines of Code : 8dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def admin_order_pdf(request, order_id):
                order = get_object_or_404(Order, id=order_id)
                pdf = open('order.pdf', "w+b")
                context = {'order': order}
                source_html = render_to_string('pdf.html', context)
            How to get rid of cryptography build error?
            Pythondot img7Lines of Code : 35dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            error: Can not find Rust compiler
            FROM python:3.7-alpine
            RUN apk add --update \
              build-base \
              cairo \
              cairo-dev \
              cargo \
              freetype-dev \
              gcc \
              gdk-pixbuf-dev \
              gettext \
            How to get rid of cryptography build error?
            Pythondot img8Lines of Code : 2dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Converting HTML Files to PNG Images
            Pythondot img9Lines of Code : 9dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from weasyprint import HTML, CSS
            div = 'your div as string'
            css_string = 'your css as string'
            html = HTML(string=div)
            css = CSS(string=css_string)
            html.write_png('output.png', stylesheets=[css])
            name 'HTML' is not defined
            Pythondot img10Lines of Code : 8dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from django.core.files.storage import FileSystemStorage
            from django.http import HttpResponse
            from django.template.loader import render_to_string
            from weasyprint import HTML
            def WeasyPDF(request):

            Community Discussions


            So can't use weasyprint what is the best thing to do?
            Asked 2021-Jun-02 at 02:17

            Thanks in advance. I am trying to load a django project onto a server. I realized I was unable to update Cairo for weasyrprint. I would like to to change the code to some thing else. I was thinking pylatex?? This is for html to pdf. In my orders app views.py



            Answered 2021-May-29 at 01:23

            I've been using xhtml2pdf for a while, and had no problems using it. You can can give it a try too!

            You can install it using the pip (Python Package Index) command:###

            pip install xhtml2pdf

            Source https://stackoverflow.com/questions/67746632


            Weaseyprint, Cairo, Dajngo on Pythonanywhere 25MAY21 can not pass a warning
            Asked 2021-Jun-01 at 22:02

            Sorry I know there seems to be a lot about this topic. But I do not see a real resolution?

            I am trying to place a Django ecommerce pizza shop for learning Django on the website. Locally this works great no issues. I matched my environment locally to that on the ENV for the server. I got this issue resolved locally when I updated Cairo on my computer. So the emulated server works great.

            Python 3.8.0 Server Pythonanywhere

            Here is the error and follow on info.

            Error from error log on ther server. 2021-05-28 16:13:41,156: /home/williamc1jones/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/weasyprint/document.py:35: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4. WeasyPrint may work with older versions, but please read the note about the needed cairo version on the "Install" page of the documentation before reporting bugs. http://weasyprint.readthedocs.io/en/latest/install.html

            views.py file in order app



            Answered 2021-Jun-01 at 22:01

            Yes I wanted to thank everyone for their help. While I have a time lime for my project I will dit the post to see my work around as well. Thanks.

            Source https://stackoverflow.com/questions/67744167


            Using awk in a bash-script
            Asked 2021-May-25 at 10:43

            I've been struggling to run an awk result as the arguments of a new awk command within a bash-script; something like this



            Answered 2021-May-25 at 10:43

            Your quoting is not really going to make it through xargs the way you would like. It's not impossible to pull off, but I would instead do something like

            Source https://stackoverflow.com/questions/67685005


            How to get rid of cryptography build error?
            Asked 2021-Apr-27 at 19:39

            I am trying to build a dockerfile but the problem is when it trying to build specifically cryptography is not building.

            MY Dockerfile



            Answered 2021-Feb-09 at 12:22


            'bytes' object has no attribute 'encode' in EmailMessage
            Asked 2021-Mar-20 at 17:52

            I am trying to make an app in Django which accepts information from user and send a HTML template as pdf through an e-mail to the user. But I am getting this error 'bytes' object has no attribute 'encode'

            Here is my view for the email



            Answered 2021-Mar-20 at 17:52

            The problem is that you're sending a PDF file object as the message body:

            Source https://stackoverflow.com/questions/66718672


            WeasyPrint unable to load images/css: Temporary failure in name resolution
            Asked 2021-Mar-08 at 19:52

            I'm using WeasyPrint 52.3 (latest version available at time of writing) along with Django 2.2 LTS on Python 3.6 on a Windows 10 development machine; all is working fine.

            However when I try to render a PDF on my Linux machine (same WeasyPrint/Django/Python versions), all items I try to load from an URI are not shown, including images and CSS. When not using WeasyPrint, images/CSS are properly loaded. My images/CSS are available at https://myhost.tld/some.css and myhost has its certs signed.

            When using inline CSS, the CSS is rendered fine.

            I've tried to enable WeasyPrint logging through:



            Answered 2021-Mar-08 at 19:52

            Ensure myhost.tld is part of the /etc/hosts file:

            Source https://stackoverflow.com/questions/66536242


            "no such file or directory" when passing full path to Docker image, but works with relative path to same folder
            Asked 2021-Feb-16 at 19:19

            From a PHP page in Apache I'm trying to run a docker command that will generate a PDF. I've added both my user and the www-data user to the docker group so they can execute a docker command without sudo.

            This works within a PHP file that exists at the /home/my_user/projects/my_project/public folder:



            Answered 2021-Feb-16 at 19:19

            On the Docker VM run ls /home/ and I would wager the directory you expect isn't there. The user referenced in your path probably doesn't exist on the VM, only on your host machine.

            The relative path works because it's relative to the root directory provided.

            Source https://stackoverflow.com/questions/66230433


            name 'HTML' is not defined
            Asked 2021-Feb-04 at 18:54

            I am working with the Django project and trying to render a pdf with WeasyPrint.

            my views.py:



            Answered 2021-Feb-04 at 18:54

            It seems like you have skipped the import part of the code in the tutorial which should be right on top of your WeasyPDF function:

            Source https://stackoverflow.com/questions/66051241


            Trouble installing turbodbc
            Asked 2021-Jan-11 at 20:49

            I am attempting to install turbodbc on my Ubuntu 20.10 machine.
            My specs are as follows: pip 20.2.4, Python 3.8.5 , gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0

            I have attempted the solutions provided in the previous posts here and and here.

            I am getting this error message



            Answered 2021-Jan-11 at 20:49

            Boost is not installed. You can try this

            Source https://stackoverflow.com/questions/65674126


            How to load a file from code instead of form field
            Asked 2021-Jan-08 at 10:04

            As I don't have much experience with python and django I would like to ask about loading a file into a variable from code.

            Here is my scenario: User sends the data to my django backend with POST with some parameters like this:



            Answered 2021-Jan-08 at 10:04

            Assuming that much of this is a work in progress...

            The PDF does not need to be "loaded into memory", I am guessing that you are trying to return the path of the newly created PDF to the API for downloading.

            The Document model can be created directly, and should not be created via dict -> serializer -> model create method.

            After creating the model, then serialize it for API output.

            I also removed the serializer.is_valid() because the data needs to be valid to get this far anyway. Consider replacing that with other error handling techniques, that would include the pdf creation, etc.

            Source https://stackoverflow.com/questions/65617158

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install WeasyPrint

            You can install using 'pip install WeasyPrint' or download it from GitHub, PyPI.
            You can use WeasyPrint like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install weasyprint

          • CLONE
          • HTTPS


          • CLI

            gh repo clone Kozea/WeasyPrint

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link