Last active
July 4, 2024 10:24
-
-
Save tzi/251bece8f7763138111c to your computer and use it in GitHub Desktop.
WeasyPrint install on a clean Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install libxml2-dev libxslt-dev libffi-dev libcairo2-dev libpango1.0-dev python-dev python-pip | |
sudo pip install WeasyPrint |
for the current version of WeasyPrint, python 3 is required. So i adjusted the commands to work with the new version:
sudo apt-get install libxml2-dev libxslt-dev libffi-dev libcairo2-dev libpango1.0-dev python-dev python3-pip
sudo pip3 install WeasyPrint
Unfortunately when I use it with Django I get...
# source venv/bin/activate
(venv) # ./mange.py shell
...
>>> from weasyprint import HTML
>>>
>>> HTML('https://en.wikipedia.org/wiki/Computer').write_pdf('/var/www/project/files/something.pdf')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/__init__.py", line 211, in write_pdf
font_config=font_config).write_pdf(
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/__init__.py", line 168, in render
font_config)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/document.py", line 393, in _render
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/document.py", line 393, in <listcomp>
[Page(page_box, enable_hinting) for page_box in page_boxes],
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/__init__.py", line 126, in layout_document
pages = list(make_all_pages(context, root_box, html, pages))
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 804, in make_all_pages
page, resume_at = remake_page(i, context, root_box, html)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 743, in remake_page
page_number, page_state)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 554, in make_page
positioned_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 507, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 507, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 507, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 507, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 507, in block_container_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 552, in block_container_layout
new_children, absolute_boxes, fixed_boxes)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 818, in find_earlier_page_break
child.children, absolute_boxes, fixed_boxes)
File "/var/www/venv/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 824, in find_earlier_page_break
resume_at = (new_child.index, resume_at)
AttributeError: 'BlockBox' object has no attribute 'index'
Anyone else having this problem?
This seems to be specific to wikipedia as HTML('https://www.example.com').write_pdf('/var/www/project/files/something.pdf')
works
sudo apt-get install libxml2-dev libxslt-dev libffi-dev libcairo2-dev libpango1.0-dev python3 python3-pip
sudo pip3 install WeasyPrint
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you