bootstrapworld / curriculum

6 stars 7 forks source link

pdftk -> pdf-lib.js (or other node equivalent) #580

Closed schanzer closed 3 years ago

schanzer commented 3 years ago

As @ds26gte points out, pdftk is a sledgehammer of a library. Currently we use it for nothing more than concatenating PDF files and adding page numbers.

Now that node packages are already part of our build system, let's investigate moving away from pdftk. If nothing else this will reduce the toolchain footprint, but it may also result in performance improvements. More tantalizingly, it would allow for workbook generation to be done on the fly, on the client.

schanzer commented 3 years ago

@ds26gte This appears to be more straightforward than I thought!

This example page just needs an list of page paths! All processing happens in the browser.

schanzer commented 3 years ago

This is largely complete on the dynamic-pagenums branch. What's needed is to run this code on node as part of the normal build, and (possibly) refactor the distribution directory into a simpler structure that mirrors the sources:

distribution/
  lessons/
    lessonA/
    lessonB/
    ...
  pathways/
    algebra/
    data-science/
    ...
lib/

The proglang, lessons, and title variables define a pathway, and page all page numbers, language tables, and workbooks can be computed (in JS!) from storing those variables in the dependency graph. The build script can just asciidoc the lessons (all of them, once for each proglang), then generate all individual PDFs. This work should probably be tracked in a separate Git issue when the time comes.

schanzer commented 3 years ago

@ds26gte This JS code computes the workbook pages from the dependency graph, then handles (1) collation, (2) page numbering, and (3) rotating pages so the title always faces the spine (#528).

If the build script can include all of the pages for a lesson in the graph, annotating which ones are in the workbook and which are not, this code could be moved to html2pdf.js, which handles all the WB processing and eliminates a lot of build-script code.