You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using this module to create PDF Files.
I need some texts alignment properties like center, left align or right align.
Does HummusJS support this one?
Because it's not useful for me to use the constant location.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
This might not be groundbreaking, but if anyone else is coming across this trying to center text here's a little function to do so. It assumes you have a box within which you want to center your text, and you use the left coordinate and the width of that box to perform the calculation. "fontObject" should be the output of getFontForFile, such as:
var fontObject = pdfWriter.getFontForFile('./TestMaterials/fonts/arial.ttf');
function CalculateLeftForCentering(fontObject, fontSize, textContent, containerLeft, containerWidth)
{
var leftForCenter = containerLeft;
var textDimensions = fontObject.calculateTextDimensions(textContent, fontSize);
var marginAmount = (containerWidth - textDimensions.width)/2;
if(marginAmount > 0)
{
leftForCenter = containerLeft + marginAmount;
}
return leftForCenter;
}
Hi,
I'm using this module to create PDF Files.
I need some texts alignment properties like center, left align or right align.
Does HummusJS support this one?
Because it's not useful for me to use the constant location.
Thanks in advance.
The text was updated successfully, but these errors were encountered: