Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text alignment for PDF #10

Closed
ziram opened this issue Sep 11, 2013 · 3 comments
Closed

text alignment for PDF #10

ziram opened this issue Sep 11, 2013 · 3 comments
Assignees

Comments

@ziram
Copy link

ziram commented Sep 11, 2013

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.

@ghost ghost assigned galkahana Sep 15, 2013
@galkahana
Copy link
Owner

nope. nothing like that. you can implement this though using the text measuring method. here: https://github.com/galkahana/HummusJS/wiki/Show-text#measuring-text

@tsestrich
Copy link

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;
}

@galkahana
Copy link
Owner

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants