# "When pages get busy": the same rows drawn with one pdf.text call each# and with a list of DrawOp values applied by one pdf.draw call; the two# pages are byte-identical. A paragraph under the table with textBlock.# Writes busy.pdf.## Run: jennifer run busy.jimport"pdf.j"as pdf;
use fs;
use io;
defconstFONTasstringinit"Helvetica";
defconstSIZEasintinit8;
defstruct Row { y asint, sku asstring };
def rows aslistof Row init [];
for (def i in0..40) {
$rows[] = Row{y: 520 - 12 * $i, sku: "A-{1000 + 7 * $i}"};
}
# One call per element: each one appends to the page's content.def slow aspdf.Page initpdf.page(842, 595);
for (def r in$rows) {
$slow = pdf.text($slow, 44, $r.y, FONT, SIZE, $r.sku);
}
# The same elements collected and applied at once.def pg aspdf.Page initpdf.page(842, 595);
def ops aslistofpdf.DrawOp init [];
for (def r in$rows) {
$ops[] = pdf.DrawOp.Text{x: 44, y: $r.y, font: FONT,
size: SIZE, str: $r.sku};
}
$pg = pdf.draw($pg, $ops);
def a asbytesinitpdf.render(pdf.addPage(pdf.document(), $slow));
def b asbytesinitpdf.render(pdf.addPage(pdf.document(), $pg));
io.printf("text calls and draw give the same bytes: %v\n", $a == $b);
# A paragraph wrapped into a 300 point column, justified.$pg = pdf.textBlock($pg, 440, 520, 300, FONT, SIZE, 11,
"Prices are per unit and exclude VAT. Quantities are counted at the "
+ "close of business on the last working day of the month; goods in "
+ "transit between stores are listed under the receiving store.",
"justify");
for (def l inpdf.wrapText(FONT, SIZE, "Short lines wrap at word boundaries.", 80)) {
io.printf("%s\n", $l);
}
fs.writeBytes("busy.pdf", pdf.render(pdf.addPage(pdf.document(), $pg)));