Pdfkit: How to make two columns of text equally spaced?

Created on 18 May 2018  路  1Comment  路  Source: foliojs/pdfkit

Hi, I've read the documentation from pdfkit.org/docs/text.html

I have trouble putting two sets of text into 2 separate columns with a columnGap of 40.

After reading the documentation, I still haven't found a way to put two words "hello world" into 1 column and another two words "bye world" into a second column on the same row as the first column.

Most helpful comment

@sc4224 You need to specify the column top left positions and the width. Try something like this:

let col1LeftPos = 50;
let colTop = 50;
let colWidth = 100;
let col2LeftPos = colWidth + col1LeftPos + 40;

doc.fontSize(16)
   .text('test col 1 test col 1 test col 1 test col 1 ', col1LeftPos, colTop, {width: colWidth})
   .text('test col 2 test col 2 test col 2 test col 2 ', col2LeftPos, colTop, {width: colWidth})

Should look like:
image

>All comments

@sc4224 You need to specify the column top left positions and the width. Try something like this:

let col1LeftPos = 50;
let colTop = 50;
let colWidth = 100;
let col2LeftPos = colWidth + col1LeftPos + 40;

doc.fontSize(16)
   .text('test col 1 test col 1 test col 1 test col 1 ', col1LeftPos, colTop, {width: colWidth})
   .text('test col 2 test col 2 test col 2 test col 2 ', col2LeftPos, colTop, {width: colWidth})

Should look like:
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephen-last picture stephen-last  路  4Comments

raesche picture raesche  路  4Comments

ramirezkevin picture ramirezkevin  路  4Comments

nqgajanan picture nqgajanan  路  4Comments

balsamiqMichele picture balsamiqMichele  路  4Comments