Code: Making PDFs with Jennifer
Making PDFs with Jennifer: the code
The programs behind the slides. They use only the pdf module that ships with the interpreter, need no decks and no network, and run with Jennifer 0.26.0. Run them from this folder or any other: each writes its PDF into the current directory. pdftotext (poppler) and qpdf are only needed to look at the results the way the slides do.
hello.j: one A4 landscape page with a title, a coloured rule and an outlined box ("Hello, PDF"). Run:jennifer run hello.j(writeshello.pdf)fonts.j:measureTextwidths, the error for a font outside the standard 14, the error for a character outside Windows-1252, andtoWinAnsi("Fonts and measuring", "The limit: WinAnsi"). Run:jennifer run fonts.j(prints only)stock.j: the whole report, 130 made-up articles on 4 pages: the layout constants,rightTextandmoney,clipwith an ellipsis,newPagewith the repeated header, the row loop with page breaks, the "Page x of y" footers in a second pass, metadata and a bookmark ("What we are building" to "Metadata, bookmarks, same bytes"). It prints130 rows on 4 pagesand the file size. Run:jennifer run stock.j(writesstock-list.pdf), thenqpdf --check stock-list.pdforpdftotext -layout stock-list.pdf -footer.j: a two-page document with aPageLabelfooter that the module stamps at render time ("Or let the module stamp it"). Run:jennifer run footer.j(writesfooter.pdf), thenpdftotext -layout footer.pdf -busy.j: rows drawn with onepdf.textcall each and withDrawOpvalues applied by onepdf.draw, compared byte for byte, plustextBlockandwrapText("When pages get busy"). Run:jennifer run busy.j(writesbusy.pdf)
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 1.7 KiB | raw |
| busy.j | 1.7 KiB | raw |
| fonts.j | 1013 B | raw |
| footer.j | 732 B | raw |
| hello.j | 594 B | raw |
| stock.j | 5.3 KiB | raw |