Text alignment in TMSFNCPDFLib

I'm using the TTMSFNCPDFLib to create a PDF file. I have used the Graphics.DrawText method and I cant see how to set the text to be right aligned in the rect supplied. I can center, left and right but I'm trying to have the output alligned on the left and right edges of the rectangle. Is this possible ?

Hi,

There are 2 ways of handling this.

Specify the Alignment property

procedure TForm28.Button1Click(Sender: TObject);
var
  p: TTMSFNCPDFLib;
  r: TRectF;
begin
  p := TTMSFNCPDFLib.Create;
  try
    p.BeginDocument('test.pdf');
    p.NewPage;
    p.Graphics.Alignment := gtaTrailing;
    r := RectF(30, 30, 100, 60);
    p.Graphics.DrawRectangle(r);
    p.Graphics.DrawText('test', r);
    p.EndDocument(True);
  finally
    p.Free;
  end;
end;

Or use the TTMSFNCGraphicsPDFEngine

procedure TForm28.Button1Click(Sender: TObject);
var
  p: TTMSFNCPDFLib;
  r: TRectF;
  g: TTMSFNCGraphicsPDFEngine;
begin
  p := TTMSFNCPDFLib.Create;
  g := TTMSFNCGraphicsPDFEngine.Create(p);
  try
    p.BeginDocument('test.pdf');
    p.NewPage;
    r := RectF(30, 30, 100, 60);
    g.DrawRectangle(r);
    g.DrawText(r, 'test', False, gtaTrailing);
    p.EndDocument(True);
  finally
    g.Free;
    p.Free;
  end;
end;

Hi Pieter,

Thanks for that. That worked for DrawText but still left justifies for DrawHtmlText with a string like

short:
longer text

Is DrawHtmlText with the Alignment set to gtaTrailing meant to right align the html text ?
I tried a few different combinations including some style options but couldnt get anything other than left justified.

For DrawHTMLText, you need to use paragraph alignment

. But it's better to switch to the TTMSFNCGraphicsPDFEngine because this one has built in alignment for both normal and HTML text.