Menu

Exact left position of text?

Help
mr.burns
2013-11-26
2013-12-01
  • mr.burns

    mr.burns - 2013-11-26

    Hi,

    I am new to TCPDF and have a question regarding positioning text.
    Lets say I have the word MOUNTAIN using the font avantgarde where the left and right edge of the M are 100 percent vertical lines.
    Now I want to postition the left edge of the letter M at position X = 20 mm on an A4 size paper.
    If I use $pdf->Cell(...) I could not get the correct X-position since between the left edge of the cell-border and the 'M' is always a small gap. Even with align = 'L' the gap still exists.

    Furthermore the gap is different (in percentage point of view).
    If the letter M has a height of 100 mm the gap is 3.5 mm.
    If the letter M has a height of 20 mm the gap is 1.0 mm (and not 20% of 3.5 mm which would be 0.7 mm)
    I also tried $pdf->setCellPadding(0) - but also without any effect, the gap is still there.
    What I need is that any text, any starting letter inside the cell starts at the left edge of the cell.

    So how I can left align MOUNTAIN so that the left edge of the M is exact at 20 mm from the left border of my A4 size paper?

    Thanks for any help!

     

    Last edit: mr.burns 2013-11-26
  • mr.burns

    mr.burns - 2013-11-28

    Hi,

    I still need some help on this topic and wonder that nobody else has/had this problem?
    Please try following simple code:

    $pdf->AddPage();

    $pdf->Line(10, 5, 10, 290); // Line to control x-position at 10 mm

    $pdf->SetCellPadding(0);

    $pdf->setXY(10, 24);
    $pdf->SetFont('', '', 48);
    $pdf->Cell(0,10,'M 48pt',0,2);

    $pdf->setXY(10, 36);
    $pdf->SetFont('', '', 96);
    $pdf->Cell(0,10,'M 96pt',0,2);

    $pdf->setXY(10, 56);
    $pdf->SetFont('', '', 192);
    $pdf->Cell(0,10,'M 192pt',0,2);

    $pdf->setXY(10, 100);
    $pdf->SetFont('', '', 384);
    $pdf->Cell(0,10,'M 384',0,2);

    $pdf->Output('test.pdf', 'I');

    This code just prints a vertical line at 10 mm from left side of the paper.
    Then it prints 5 lines with letter M and the size in pt at position 10, ...
    using setXY(10, ...)

    As you can see in the attached test.pdf none of the letters M are left aligned to the vertical line even if I set the pointer/curser to 10mm using setXY(10, ...);
    If the font size gets bigger the distance gets bigger.
    For the font size of 384 pt the distance is 10 mm, for 192 pt it is 5 mm, so it seems there is a linear relationship.
    But if I use a different font the distance for 384 pt is no longer 10mm. For e.g. AvantGarde it is 9.5 mm.

    What we can see now is that there is a linear relationship between distance and fontsize.
    And we can see that the distance is depending on the font.

    Is there no way to get rid of this gap between the letter and the vertical line?
    I tried also with setCellPadding(0), but it has no effect :-(.
    There must be a possibility for exact font positioning or not???

    Please, please help me...

     

    Last edit: mr.burns 2013-11-28
  • Nicola Asuni

    Nicola Asuni - 2013-12-01

    Please check the example n.57 for various cell metrics, including internal padding.

     

Log in to post a comment.

MongoDB Logo MongoDB