How to set characterSpacing from pt/px?
How to set lineHeight from pt/px?
I just can not understand how to translate from points or pixels into a value for pdfkit. Help me please
I need to convert html text to pdf. And you need to match the letter spacing and the line spacing.
CSS: Font - 18pt; LineHeight - 1.4 (not pt); letterSpacing - 2pt;
How to set this in pdfkit?
doc.text(element.content, element.left, element.top, {
width : element.width,
align : element.properties.textAlign,
characterSpacing : 2, //???
lineBreak : false,
lineGap : 1.4, //????
});
How to set characterSpacing from pt/px?
How to set lineHeight from pt/px?
I just can not understand how to translate from points or pixels into a value for pdfkit. Help me please
https://github./devongovett/pdfkit
I need to convert html text to pdf. And you need to match the letter spacing and the line spacing.
CSS: Font - 18pt; LineHeight - 1.4 (not pt); letterSpacing - 2pt;
How to set this in pdfkit?
doc.text(element.content, element.left, element.top, {
width : element.width,
align : element.properties.textAlign,
characterSpacing : 2, //???
lineBreak : false,
lineGap : 1.4, //????
});
Share
Improve this question
edited Mar 5, 2018 at 15:22
Floyat
asked Mar 5, 2018 at 14:09
FloyatFloyat
1611 gold badge2 silver badges5 bronze badges
1
- 1 show us some code, what you have already tried – nattfodd Commented Mar 5, 2018 at 14:16
2 Answers
Reset to default 2When using pdfKit, measurements are in points where 72 points is 1 inch. So characterSpacing is how many "points" between each character. In the example provided of 2, it would be 2 points or 2/72 of an inch.
The lineGap, is the number of points between lines of text. For example, lineGap: 10 is 10/72 of an inch. This represents the space between the bottom of one row and the top of the subsequent row.
This is different than line-height in HTML, where line-height is more like a multiplier of the specified line height.
This is how it works for me, I hope it helps someone
doc
.fontSize(10)
.font('Helvetica-Bold')
.lineGap(5)
.text('your text', 50, 50, { align: 'right' });
// positioning of your text first 50 is for x, second for y