How to Draw Centered Text
Delphi
[copy to clipboard]
// PDF object is supposed to be created
str := 'Centered text.';
fnt := PDF.AddBuiltInFont(bfTimesRoman, false, false);
PDF.UseFont(fnt, 40);
w := PDF.GetUnicodeTextWidth(str);
h := PDF.GetUnicodeTextHeight(str);
PDF.ShowTextAt((PDF.PageWidth - w) / 2, (PDF.PageHeight - h) / 2, str);
PDF.SaveToFile('test.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created
wstring str = L"Centered text.";
long fnt = PDF->AddBuiltInFont(bfTimesRoman, false, false);
PDF->UseFont(fnt, 40);
float w = PDF->GetUnicodeTextWidth(str);
float h = PDF->GetUnicodeTextHeight(str);
PDF->ShowTextAt((PDF->PageWidth - w) / 2, (PDF->PageHeight - h) / 2, str);
PDF->SaveToFile("test.pdf", true);
// PDF object is supposed to be created
string str = "Centered text.";
long fnt = PDF.AddBuiltInFont(BuiltInFont.bfTimesRoman, false, false);
PDF.UseFont(fnt, 40);
float w = PDF.GetUnicodeTextWidth(str);
float h = PDF.GetUnicodeTextHeight(str);
PDF.ShowTextAt((PDF.PageWidth - w) / 2, (PDF.PageHeight - h) / 2, str);
PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
str = "Centered text."
fnt = PDF.AddBuiltInFont(0, false, false) 'BuiltInFont.bfTimesRoman = 0
PDF.UseFont fnt, 40
w = PDF.GetUnicodeTextWidth(str)
h = PDF.GetUnicodeTextHeight(str)
PDF.ShowTextAt (PDF.PageWidth - w) / 2, (PDF.PageHeight - h) / 2, str
PDF.SaveToFile "test.pdf", true