Skip to content

ets#

ets is a JavaScript frontend for boxes and glue.

Installation#

See the Readme file in the repository.

First document#

bag = require("bag:backend/bag")
fe = require("bag:frontend")

const f = fe.new("out.pdf")
const str = `In olden times when wishing still helped one, there lived a king whose
daughters were all beautiful; and the youngest was so beautiful that the sun itself,
which has seen so much, was astonished whenever it shone in her face.
Close by the king’s castle lay a great dark forest, and under an old lime-tree in the
forest was a well, and when the day was very warm, the king’s child went out into the
forest and sat down by the side of the cool fountain; and when she was bored she
took a golden ball, and threw it up on high and caught it; and this ball was her
favorite plaything.`.replace(/\s+/g, ' ').trim()

const ff = f.newFontFamily("text");
ff.addMember(fe.fontSource("CrimsonPro-Bold.ttf"), fe.fontWeight700, fe.fontStyleNormal);
ff.addMember(fe.fontSource("CrimsonPro-Regular.ttf"), fe.fontWeight400, fe.fontStyleNormal);
const para = fe.newText();

para.settings[fe.settingSize] = 12 * bag.factor;
para.items.push(str);

const ret = f.formatParagraph(para, bag.mustSP("125pt"), fe.leading(14 * bag.factor), fe.family(ff));
const p = f.doc.newPage();
p.outputAt(bag.mustSP("1cm"), bag.mustSP("26cm"), ret[0]);
p.shipout();
f.doc.finish();

Now run (on the command line)

ets myfile.js

which creates a PDF (out.pdf) and a log file (myfile-protocol.xml).

Lowercase field names#

If you are familiar with boxes and glue, you will see the similarities between both interfaces. For example the boxes and glue method Shipout() of the page object is shipout() in the JavaScript interface.

Example documents#

There is a section of ets documents in the examples repository on GitHub.