Вы находитесь на странице: 1из 5

By default paragraphs are stacked one on top of (or actually - below) another.

It's possible however to split any paragraph (or even the whole document) into columns.

Here we go with 2 star-sized columns, with justified text and gap set to 20:

Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Malit profecta versatur nomine adipisicing elit. Malit profecta versatur nomine
ocurreret multavit, officiis viveremus aeternum ocurreret multavit, officiis viveremus aeternum
superstitio suspicor alia nostram, quando superstitio suspicor alia nostram, quando
nostros congressus susceperant concederetur nostros congressus susceperant concederetur
leguntur iam, vigiliae democritea tantopere leguntur iam, vigiliae democritea tantopere
causae, atilii plerumque ipsas potitur causae, atilii plerumque ipsas potitur
pertineant multis rem quaeri pro, legendum pertineant multis rem quaeri pro, legendum
didicisse credere ex maluisset per videtis. Cur didicisse credere ex maluisset per videtis. Cur
discordans praetereat aliae ruinae dirigentur discordans praetereat aliae ruinae dirigentur
orestem eodem, praetermittenda divinum. orestem eodem, praetermittenda divinum.
Collegisti, deteriora malint loquuntur officii Collegisti, deteriora malint loquuntur officii
cotidie finitas referri doleamus ambigua acute. cotidie finitas referri doleamus ambigua acute.
Adhaesiones ratione beate arbitraretur Adhaesiones ratione beate arbitraretur
detractis perdiscere, constituant hostis detractis perdiscere, constituant hostis
polyaeno. Diu concederetur. polyaeno. Diu concederetur.

Star-sized columns have always equal widths, so if we define 3 of those, it'll look like this (make
sure to scroll to the next page, as we have a couple of more examples):

Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet,
consectetur adipisicing elit. consectetur adipisicing elit. consectetur adipisicing elit.
Malit profecta versatur Malit profecta versatur Malit profecta versatur
nomine ocurreret multavit, nomine ocurreret multavit, nomine ocurreret multavit,
officiis viveremus aeternum officiis viveremus aeternum officiis viveremus aeternum
superstitio suspicor alia superstitio suspicor alia superstitio suspicor alia
nostram, quando nostros nostram, quando nostros nostram, quando nostros
congressus susceperant congressus susceperant congressus susceperant
concederetur leguntur iam, concederetur leguntur iam, concederetur leguntur iam,
vigiliae democritea tantopere vigiliae democritea tantopere vigiliae democritea tantopere
causae, atilii plerumque ipsas causae, atilii plerumque ipsas causae, atilii plerumque ipsas
potitur pertineant multis rem potitur pertineant multis rem potitur pertineant multis rem
quaeri pro, legendum quaeri pro, legendum quaeri pro, legendum
didicisse credere ex didicisse credere ex didicisse credere ex
maluisset per videtis. Cur maluisset per videtis. Cur maluisset per videtis. Cur
discordans praetereat aliae discordans praetereat aliae discordans praetereat aliae
ruinae dirigentur orestem ruinae dirigentur orestem ruinae dirigentur orestem
eodem, praetermittenda eodem, praetermittenda eodem, praetermittenda
divinum. Collegisti, deteriora divinum. Collegisti, deteriora divinum. Collegisti, deteriora
malint loquuntur officii malint loquuntur officii malint loquuntur officii
cotidie finitas referri cotidie finitas referri cotidie finitas referri
doleamus ambigua acute. doleamus ambigua acute. doleamus ambigua acute.
Adhaesiones ratione beate Adhaesiones ratione beate Adhaesiones ratione beate
arbitraretur detractis arbitraretur detractis arbitraretur detractis
perdiscere, constituant hostis perdiscere, constituant hostis perdiscere, constituant hostis
polyaeno. Diu concederetur. polyaeno. Diu concederetur. polyaeno. Diu concederetur.

You can also specify accurate widths for some (or all columns). Let's make the first column and
the last one narrow and let the layout engine divide remaining space equally between other star-
columns:

Lorem ipsum Lorem ipsum dolor sit Lorem ipsum dolor sit Lorem ipsum
dolor sit amet, amet, consectetur amet, consectetur dolor sit amet,
consectetur adipisicing elit. Malit adipisicing elit. Malit consectetur
adipisicing elit. profecta versatur nomine profecta versatur nomine adipisicing elit.
Malit profecta ocurreret multavit, officiis ocurreret multavit, officiis Malit profecta
versatur nomine viveremus aeternum viveremus aeternum versatur nomine
ocurreret superstitio suspicor alia superstitio suspicor alia ocurreret
multavit, officiis nostram, quando nostros nostram, quando nostros multavit, officiis
viveremus congressus susceperant congressus susceperant viveremus
aeternum concederetur leguntur concederetur leguntur aeternum
superstitio iam, vigiliae democritea iam, vigiliae democritea superstitio
suspicor alia tantopere causae, atilii tantopere causae, atilii suspicor alia
nostram, quando plerumque ipsas potitur plerumque ipsas potitur nostram, quando
nostros pertineant multis rem pertineant multis rem nostros
congressus quaeri pro, legendum quaeri pro, legendum congressus
susceperant didicisse credere ex didicisse credere ex susceperant
concederetur maluisset per videtis. Cur maluisset per videtis. Cur concederetur
leguntur iam, discordans praetereat discordans praetereat leguntur iam,
vigiliae aliae ruinae dirigentur aliae ruinae dirigentur vigiliae
democritea orestem eodem, orestem eodem, democritea
tantopere praetermittenda divinum. praetermittenda divinum. tantopere
causae, atilii Collegisti, deteriora Collegisti, deteriora causae, atilii
plerumque ipsas malint loquuntur officii malint loquuntur officii plerumque ipsas
potitur cotidie finitas referri cotidie finitas referri potitur
pertineant doleamus ambigua doleamus ambigua pertineant
multis rem acute. Adhaesiones acute. Adhaesiones multis rem
quaeri pro, ratione beate arbitraretur ratione beate arbitraretur quaeri pro,
legendum detractis perdiscere, detractis perdiscere, legendum
didicisse constituant hostis constituant hostis didicisse
credere ex polyaeno. Diu polyaeno. Diu credere ex
maluisset per concederetur. concederetur. maluisset per
videtis. Cur videtis. Cur
discordans discordans
praetereat aliae praetereat aliae
ruinae dirigentur ruinae dirigentur
orestem eodem, orestem eodem,
praetermittenda praetermittenda
divinum. divinum.
Collegisti, Collegisti,
deteriora malint deteriora malint
loquuntur officii loquuntur officii
cotidie finitas cotidie finitas
referri doleamus referri doleamus
ambigua acute. ambigua acute.
Adhaesiones Adhaesiones
ratione beate ratione beate
arbitraretur arbitraretur
detractis detractis
perdiscere, perdiscere,
constituant constituant
hostis polyaeno. hostis polyaeno.
Diu Diu
concederetur. concederetur.

We also support auto columns. They set their widths based on the content:

auto This is a star-sized this one another This is a star-sized


column column. It should get the has auto column. It should get the
remaining space divided specific column remaining space divided
by the number of all star- width set by the number of all star-
sized columns. to 50 sized columns.

If all auto columns fit within available width, the table does not occupy whole space:

val1 val2 value3 value 4

Another cool feature of pdfmake is the ability to have nested elements. Each column is actually
quite similar to the whole document, so we can have inner paragraphs and further divisions, like
in the following example:

Lorem ipsum dolor sit As you can see in the document definition - this column is not defined with
amet, consectetur
adipisicing elit. an object, but an array, which means it's treated as an array of paragraphs
Conveniunt quieti rendered one below another.
extremum severitatem Just like on the top-level of the document. Let's try to divide the remaing
disseretur virtute locum
virtus declarant. Greges space into 3 star-sized columns:
telos detrimenti persius
possint eripuit appellat Lorem ipsum dolor sit Lorem ipsum dolor sit Lorem ipsum dolor sit
democrito suscipere
existimant. Facere usus amet, consectetur amet, consectetur amet, consectetur
levitatibus confirmavit, adipisicing elit. Malit adipisicing elit. Malit adipisicing elit. Malit
provincia rutilius libris profecta versatur profecta versatur profecta versatur
accommodare
valetudinis ignota nomine ocurreret nomine ocurreret nomine ocurreret
fugienda arbitramur multavit, officiis multavit, officiis multavit, officiis
falsarum commodius. viveremus aeternum viveremus aeternum viveremus aeternum
Voluptas summis
arbitrarer cognitio superstitio suspicor superstitio suspicor superstitio suspicor
temperantiamque, fuit alia nostram, quando alia nostram, quando alia nostram, quando
posidonium pro nostros congressus nostros congressus nostros congressus
assueverit animos
inferiorem, affecti susceperant susceperant susceperant
honestum ferreum cum concederetur leguntur concederetur leguntur concederetur leguntur
tot nemo ius partes iam, vigiliae iam, vigiliae iam, vigiliae
dissensio opinor, tuum
intellegunt numeris democritea tantopere democritea tantopere democritea tantopere
ignorant, odia diligenter causae, atilii causae, atilii causae, atilii
licet, sublatum repellere, plerumque ipsas plerumque ipsas plerumque ipsas
maior ficta severa
quantum mortem. Aut potitur pertineant potitur pertineant potitur pertineant
evertitur impediri multis rem quaeri pro, multis rem quaeri pro, multis rem quaeri pro,
vivamus. legendum didicisse legendum didicisse legendum didicisse
credere ex maluisset credere ex maluisset credere ex maluisset
per videtis. Cur per videtis. Cur per videtis. Cur
discordans praetereat discordans praetereat discordans praetereat
aliae ruinae dirigentur aliae ruinae dirigentur aliae ruinae dirigentur
orestem eodem, orestem eodem, orestem eodem,
praetermittenda praetermittenda praetermittenda
divinum. Collegisti, divinum. Collegisti, divinum. Collegisti,
deteriora malint deteriora malint deteriora malint
loquuntur officii loquuntur officii loquuntur officii
cotidie finitas referri cotidie finitas referri cotidie finitas referri
doleamus ambigua doleamus ambigua doleamus ambigua
acute. Adhaesiones acute. Adhaesiones acute. Adhaesiones
ratione beate ratione beate ratione beate
arbitraretur detractis arbitraretur detractis arbitraretur detractis
perdiscere, perdiscere, perdiscere,
constituant hostis constituant hostis constituant hostis
polyaeno. Diu polyaeno. Diu polyaeno. Diu
concederetur. concederetur. concederetur.

Oh, don't forget, we can use everything from styling examples (named styles, custom overrides)
here as well.

For instance - our next paragraph will use the 'bigger' style (with fontSize set to 15 and italics -
true). We'll split it into three columns and make sure they inherit the style:

First column (BTW - it's In this column, Last column does


defined as a single not override any
string value. pdfmake we've overriden
will turn it into fontSize to 20. It styling properties,
appropriate structure means the but applies a new
automatically and make style (header) to
sure it inherits the content should itself. Eventually -
styles have italics=true texts here have
(inherited from italics=true (from
the style) and be bigger) and derive
a little bit bigger fontSize from the
style. OK, but which
one? Both styles
define it. As we
already know from
our styling
examples, multiple
styles can be
applied to the
element and their
order is important.
Because 'header'
style has been set
after 'bigger' its
fontSize takes
precedence over
the fontSize from
'bigger'. This is how
it works. You will
find more examples
in the unit tests.

Wow, you've read the whole document! Congratulations :D