You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 KiB

Collective playcard generating time!

Git cheatsheet

git pull

git status

git log

git add filename.txt

git commit -m "my short summary of what has changed"

git push

Generate playcard.pdf with Weasyprint

We are using Weasyprint version 52.5 on the Soupboat. The latest version is 54.1 (https://github.com/Kozea/WeasyPrint/releases), but from version 53 on you need to have libpango version 1.44 installed, and on the current version of Raspian OS (the operating system of the Soupboat) we can only have libpango version 1.42. So we will stay with Weasyprint v52.

$ sudo pip3 install weasyprint==52.5

You can use Weasyprint as a Python library or from the command line.

Weasyprint as Python library

In [19]:
from weasyprint import HTML, CSS

HTML(filename='playcard.html').write_pdf('playcard.pdf', stylesheets=[CSS(filename='playcard.css')])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_22626/3089759157.py in <module>
      1 from weasyprint import HTML, CSS
      2 
----> 3 HTML(filename='playcard.html').write_pdf('playcard.pdf', stylesheets=[CSS(filename='playcard.css')])

/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py in write_pdf(self, target, stylesheets, zoom, attachments, finisher, presentational_hints, optimize_size, font_config, counter_style, image_cache)
    184 
    185         :type target: str, pathlib.Path or file object
--> 186         :param target:
    187             A filename where the PDF file is generated, a file object, or
    188             :obj:`None`.

/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py in render(self, stylesheets, presentational_hints, optimize_size, font_config, counter_style, image_cache)
    134         return get_html_metadata(self.wrapper_element, self.base_url)
    135 
--> 136     def render(self, stylesheets=None, enable_hinting=False,
    137                presentational_hints=False, optimize_images=False,
    138                font_config=None, counter_style=None, image_cache=None):

/usr/local/lib/python3.7/dist-packages/weasyprint/document.py in _render(cls, html, stylesheets, presentational_hints, optimize_size, font_config, counter_style, image_cache)

/usr/local/lib/python3.7/dist-packages/weasyprint/document.py in <listcomp>(.0)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/__init__.py in layout_document(html, root_box, context, max_loops)
    131             _, _, _, page_state, remake_state = page_data
    132             page_counter_values = page_state[1]
--> 133             page_counter_values['pages'] = [actual_total_pages]
    134             if remake_state['content_changed']:
    135                 reloop_content = True

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/page.py in make_all_pages(context, root_box, html, pages)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/page.py in remake_page(index, context, root_box, html)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/page.py in make_page(context, root_box, page_type, resume_at, page_number, page_state)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout_switch(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_box_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_container_layout(context, box, bottom_space, skip_stack, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in _in_flow_layout(context, box, index, child, new_children, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, bottom_space, position_y, skip_stack, first_letter_style, draw_bottom_decoration, collapsing_with_children, discard, next_page)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout_switch(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_box_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_container_layout(context, box, bottom_space, skip_stack, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in _in_flow_layout(context, box, index, child, new_children, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, bottom_space, position_y, skip_stack, first_letter_style, draw_bottom_decoration, collapsing_with_children, discard, next_page)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_level_layout_switch(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_box_layout(context, box, bottom_space, skip_stack, containing_block, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in block_container_layout(context, box, bottom_space, skip_stack, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, discard)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/block.py in _linebox_layout(context, box, index, child, new_children, page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins, bottom_space, position_y, skip_stack, first_letter_style, draw_bottom_decoration)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/inline.py in iter_line_boxes(context, box, position_y, bottom_space, skip_stack, containing_block, absolute_boxes, fixed_boxes, first_letter_style)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/inline.py in get_next_linebox(context, linebox, position_y, bottom_space, skip_stack, containing_block, absolute_boxes, fixed_boxes, first_letter_style)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/inline.py in split_inline_box(context, box, position_x, max_x, bottom_space, skip_stack, containing_block, absolute_boxes, fixed_boxes, line_placeholders, waiting_floats, line_children)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/inline.py in split_inline_level(context, box, position_x, max_x, bottom_space, skip_stack, containing_block, absolute_boxes, fixed_boxes, line_placeholders, waiting_floats, line_children)

/usr/local/lib/python3.7/dist-packages/weasyprint/layout/inline.py in split_text_box(context, box, available_width, skip)

/usr/local/lib/python3.7/dist-packages/weasyprint/text/line_break.py in split_first_line(text, style, context, max_width, justification_spacing, minimum)

/usr/local/lib/python3.7/dist-packages/weasyprint/text/line_break.py in create_layout(text, style, context, max_width, justification_spacing)

/usr/local/lib/python3.7/dist-packages/weasyprint/text/line_break.py in __init__(self, context, font_size, style, justification_spacing, max_width)

/usr/local/lib/python3.7/dist-packages/weasyprint/text/line_break.py in setup(self, context, font_size, style)

/usr/local/lib/python3.7/dist-packages/cffi/api.py in __getattr__(self, name)
    910     class FFILibrary(object):
    911         def __getattr__(self, name):
--> 912             make_accessor(name)
    913             return getattr(self, name)
    914         def __setattr__(self, name, value):

/usr/local/lib/python3.7/dist-packages/cffi/api.py in make_accessor(name)
    906                 if name not in accessors:
    907                     raise AttributeError(name)
--> 908             accessors[name](name)
    909     #
    910     class FFILibrary(object):

/usr/local/lib/python3.7/dist-packages/cffi/api.py in accessor_function(name)
    836         tp, _ = ffi._parser._declarations[key]
    837         BType = ffi._get_cached_btype(tp)
--> 838         value = backendlib.load_function(BType, name)
    839         library.__dict__[name] = value
    840     #

AttributeError: function/symbol 'pango_context_set_round_glyph_positions' not found in library 'libpango-1.0.so.0': /lib/arm-linux-gnueabihf/libpango-1.0.so.0: undefined symbol: pango_context_set_round_glyph_positions

Weasyprint from the command line

In [16]:
! weasyprint --help
usage: weasyprint [-h] [--version] [-i] [-e ENCODING] [-s STYLESHEET]
                  [-m MEDIA_TYPE] [-u BASE_URL] [-a ATTACHMENT] [-p]
                  [-O {images,fonts,all,none}] [-v] [-d] [-q]
                  input output

Renders web pages to PDF.

positional arguments:
  input                 URL or filename of the HTML input, or - for stdin
  output                Filename where output is written, or - for stdout

optional arguments:
  -h, --help            show this help message and exit
  --version             Print WeasyPrint's version number and exit.
  -i, --info            Print system information and exit.
  -e ENCODING, --encoding ENCODING
                        Character encoding of the input
  -s STYLESHEET, --stylesheet STYLESHEET
                        URL or filename for a user CSS stylesheet. May be
                        given multiple times.
  -m MEDIA_TYPE, --media-type MEDIA_TYPE
                        Media type to use for @media, defaults to print
  -u BASE_URL, --base-url BASE_URL
                        Base for relative URLs in the HTML input. Defaults to
                        the input's own filename or URL or the current
                        directory for stdin.
  -a ATTACHMENT, --attachment ATTACHMENT
                        URL or filename of a file to attach to the PDF
                        document
  -p, --presentational-hints
                        Follow HTML presentational hints.
  -O {images,fonts,all,none}, --optimize-size {images,fonts,all,none}
                        Optimize output size for specified features.
  -v, --verbose         Show warnings and information messages.
  -d, --debug           Show debugging messages.
  -q, --quiet           Hide logging messages.
In [20]:
! weasyprint playcard.html playcard.pdf
In [21]:
! weasyprint -s playcard.css playcard.html playcard.pdf
In [ ]: