Questions tagged [weasyprint]

WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing.

WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing. WeasyPrint is free software made available under a BSD license.

It is based on various libraries but not on a full rendering engine like WebKit or Gecko. The CSS layout engine is written in Python, designed for pagination, and meant to be easy to hack on.

Information from: https://weasyprint.org/

263 questions
25
votes
5 answers

PDF output using Weasyprint not showing images (Django)

I am trying to output PDF on Django using the Weasyprint library, but the images don't appear on the generated PDF. I have tried both relative and static URLs for the images, but even the static URL doesn't show the image. When opening the HTML…
선풍기
  • 891
  • 1
  • 7
  • 11
17
votes
5 answers

gobject-2.0-0 not able to load on macbook

I am facing this error when I start my flask application on Python3 and Mac OS: OSError: cannot load library 'gobject-2.0-0': dlopen(gobject-2.0-0, 2): image not found. Additionally, ctypes.util.find_library() did not manage to locate a library…
17
votes
2 answers

WeasyPrint page size wrong. (8.27in x 11.69 in)

I am working on a project that uses WeasyPrint to output documents. for the life of me I cannot figure out why it is defaulting the page size to a non standard page size. I would expect it to default to 8.5 x 11 inches. instead the pdfs come out as…
Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91
14
votes
3 answers

Generate PDF with WeasyPrint having common header/footer and pagination

I am using WeasyPrint to generate PDF in Django. I can generate pdf from a static html file like below - from django.template import Context, Template import weasyprint with open('static_file.html', 'r') as myfile: html_str =…
13
votes
1 answer

WeasyPrint always generating single-page PDFs from Zurb Ink

Generating a PDF from an email (Zurb Ink templated); but am always presented with a single page PDF. Runnable test-case: from weasyprint import HTML, CSS from urllib2 import urlopen if __name__ == '__main__': html =…
A T
  • 13,008
  • 21
  • 97
  • 158
12
votes
3 answers

cannot load library libcairo

I have problem when trying to run a website in Django: OSError: no library called "libcairo-2" was found cannot load library 'libcairo.so.2': /lib/x86_64-linux-gnu/libfontconfig.so.1: undefined symbol: FT_Done_MM_Var cannot load library…
alis01
  • 169
  • 1
  • 3
  • 11
12
votes
3 answers

Getting "OSError: dlopen() failed to load a library: cairo / cairo-2" on Windows

I'm getting OSError: dlopen() failed to load a library: cairo / cairo-2 when trying to execute Django after a new install. Using Windows. I'm using Weasyprint, seems to be related to that one, according to the full trace: Unhandled exception in…
SaeX
  • 17,240
  • 16
  • 77
  • 97
12
votes
2 answers

Django WeasyPrint CSS integration warning: Relative URI reference without a base URI: at line None

I want to generate reports using WeasyPrint in Django. But I don't know how to integrate the css (specifically the bootstrap css file). I am able to see the generated html. But I get a warning when I add this line to my template-
aishpant
  • 903
  • 10
  • 19
12
votes
2 answers

Django-Weasyprint image issue

As it says in the docs page, I defined a img tag in my html file as follows: This url exists in the server and I even made a different view with a http response and the image is displayed just fine. Here is…
Alvaro
  • 11,797
  • 9
  • 40
  • 57
11
votes
5 answers

OSError: cannot load library 'gobject-2.0': error 0x7e

I installed the package weasyprint according to the instructions Installing weasyprint (Django project). My system: win 10. I have installed gtk3 and it is present in my PATH import weasyprint ... @staff_member_required def order_admin_pdf(request,…
Echo Foe
  • 398
  • 1
  • 2
  • 16
10
votes
2 answers

ctypes.util.find_library() did not manage to locate a library called 'pango-1.0-0' UBUNTU SERVER (EC2)

I am setting up my EC2 instance on AWS with an UBUNTU 18.04 and running into the following error when trying to run this gunicorn command gunicorn --bind 0.0.0.0:8000 zipherJobCards.wsgi:application error: OSError: cannot load library 'pango-1.0-0':…
Kyle
  • 169
  • 1
  • 8
10
votes
4 answers

How to use custom font with weasyprint

I have a django app and I would like to create a pdf from my django view. I use weasyprint, and for some reason it doesn't accept my custom font. The font url is working and when I render the same html with the same font-face, I see the correct…
alexarsh
  • 5,123
  • 12
  • 42
  • 51
10
votes
1 answer

Weasyprint pdf does not fit to page

I have an html page with simple css2 rules. All of the content is contained in a div, which is 930px wide. In the browser, this looks as expected, and when printing (from chrome) it fits neatly to the page with a decent font size. Once I try to…
Eldamir
  • 9,888
  • 6
  • 52
  • 73
10
votes
4 answers

Python selenium test gets stuck in urlopen

My app relies on: Python 3 Django 1.8 Weasyprint Selenium It runs flawlessly on dev and production environment, but not while testing with selenium. Using weasyprint, I create a PDF from HTML, this library uses urllib to download CSS (e.g.…
SebCorbin
  • 1,645
  • 1
  • 12
  • 23
9
votes
2 answers

How to remove margins from PDF? (Generated using WeasyPrint)

I am trying to render a PDF document within my Flask application. For this, I am using the following HTML template: