Html-to-print as a lay-out tool

Pad: pad.constantvzw.org/p/prado_workshop_weasyprint
Repository: gitlab.constantvzw.org/algolit/prado-weasyprint-workshop

Anaïs Berck

anaisberck.be

Open Source Publishing

Graphic design collective using only Free/Libre Open Source Software.

osp.kitchen

Algolit

Research group exploring the potential of algorithmic literature.

algolit.net

Algoliterary encounter

PDF of the publication
Git repository

Data Workers

PDF of the publication
Git repository

Data Workers

diversions.constantvzw.org
PDF of the publication
Run it online
Git repository

Tools of today

HTML + CSS

A web browser!

Python

Scripting language.

To see if it's installed: open a terminal and type:

python3 --version

Expected output, a number like:

Python 3.6.9

If you don't have python installed it might be:

Command not found

Download python: https://www.python.org/downloads/

Weasyprint

Python library to convert HTML + CSS to a PDF

Install through the terminal:

pip3 install weasyprint

Directly from commandline

weasyprint http://weasyprint.org weasyprint-website.pdf

As library in a script

from weasyprint import HTML

HTML(filename=html_filename).write_pdf(output_pdf_filename)

CSS: Control page size

@page {
  /* width and height. In this case for an A5 */
  size: 148.5mm 210mm;
  /* OR */
  /* size: A5 portrait;  */
  padding: 0;
  marks: crop;
  bleed: 5mm;
  margin: 25mm;
  /* Bigger bleed as weasyprint draws the cropmarks within the bleed*/
}

CSS: Page numbers

@page {
  @bottom-center {
    /**
      On every page display the value of the page counter at the bottom center.
      The page counter is a special counter created by weasyprint.
      */
    content: counter(page);
  }
}

CSS: Fancy page numbers

@page:right {
  /**
    Use a pseudo-selector on the page to display page numbers on right pages 
    on the right.
    */
  @bottom-right {
    content: counter(page);
  }
}

@page:left {  
  /**
    Use a pseudo-selector on the page to display page numbers on left pages 
    on the left.
    */
  @bottom-left {
    content: counter(page);
  }
}

CSS: Special pages

@page:first {
  /**
    Selects the first page of the documents. Allows for example for hiding
    the page numbers on the cover and / or different page margins there.
    */
}


@page:empty {
  /**
    According to the standards this selector should select empty pages.
    In my experience it doesn't always work.
    */
}

CSS: Running headers

h1 {
  /** 
    When a header 1 is encoutered set the value of the string
    running-header to the value of the header
  */
  string-set: running-header content(text);
}

@page {
  @bottom-center {
    /**
      On every page display the value of running-header at
      that moment
    */
    content: string(running-header);
  }
}