Newspaper generator

From Hackers and Designers
Jump to navigation Jump to search
MainNavigation No



NDSM newspaper 2019 generator


Script to auto-generate a book from a bunch of documents downloaded from Google docs as HTML files. The script will remove most of the CSS and combine all the documents in one file: build/book.html. Then Weasyprint converts the HTML to PDF. The fonts used are all open source fonts.


Make sure you have weasyprint installed as per instructions :


On mac you'll have to install some stuff with Homebrew, so read the guide.

Install the requirements from file:

pip install -r requirements.txt


Export the documents as HTML (File > Download > HTML page...) from Google docs and place in ./srcdocs

Run clean command

Google docs places a lot of representational css inline in the document. This command cleans most of that up. We only leave the font-weight and font-style rules because we actually need those. The cleaned documents will be placed in ./build/clean. Adjust those as needed. By default is searches for files in the .srcdocs folder

python --clean

Or specify source folder: python --clean --input ./srcdocs_en

Run build command

This will combine all the files in ./build/clean by getting the contents of the document body and wrapping that in an <article> tag. The combined document will be saved as ./build/book.html and this file is used by Weasyprint to generate ./build/book-<date>.html and ./build/book-<date>.pdf

python --build

optionally Set the output filename by adding --output [filename]

python --build --output ndsm_papger.pdf

Create PDF from preexisting html

This option allow for small text changes. To do that edit the generated /build/book-<date>.html and pass that to the --html flag

python --html book-2019-0920-143629.html


Clean the input html and generate a Pdf

python --clean --input ./srcdocs_en && python --build



We had a problem with a Cairo version, so we had to force a version with pip install cairocf==0.9.0

We had locale errors on some machines. Set locale with: export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 or add those to the shells .rc file


  • Todo. Add links to font authors