THPDFPage.UserWidth

THPDFPage

 

Top  Previous  Next

Returns the page width measured in drawing units, i.e. 1/THotPDF.Resolution inch

 

Delphi syntax:

property UserWidth: Single; // read-only

 

C++ syntax:

__property float UserWidth = {read=GetUserWidth};

 

Description

X coordinates, margins, font sizes and the values TextWidth and TextHeight return are all expressed in 1/Resolution inch. Width stores the page width in points and expects points when you assign it, so at any Resolution other than 72 it will not match the coordinates you draw with. Read UserWidth whenever the page width has to be compared or combined with drawing coordinates — finding the right margin edge, centring a block or deciding when content must move onto the next page, for instance

At the default Resolution of 72, UserWidth matches Width. A page sized through Width and Height draws in points regardless of the Resolution, and UserWidth then matches Width too

 

Code Example

program RightAlignedText;
{$APPTYPE CONSOLE}
uses
  SysUtils,
  HPDFDoc;

var
  HPDF: THotPDF;
  Text: AnsiString;
  X: Single;

begin
  HPDF:= THotPDF.Create(nil);
  try
    HPDF.FileName:= 'RightAlignedText.pdf';
    HPDF.Resolution:= 144;                    // Coordinates in 1/144 inch
    HPDF.BeginDoc;
    HPDF.CurrentPage.SetFont('Arial', [], 24); // 12 pt
    Text:= 'Right aligned with a one inch margin';
    // UserWidth is 1190 on an A4 page here; Width stays 595 points
    X:= HPDF.CurrentPage.UserWidth- 144- HPDF.CurrentPage.TextWidth(Text);
    HPDF.CurrentPage.TextOut(X, 144, 0, Text);
    HPDF.EndDoc;
  finally
    HPDF.Free;
  end;
end.

 

See also: Width, UserHeight, THotPDF.Resolution