THPDFPage.UserWidth

THPDFPage

 

Top  Previous  Next

Returns the width of the page in drawing units, 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 returned by TextWidth and TextHeight are in 1/Resolution inch. Width keeps the page width in points and takes points when you set it, so with a Resolution other than 72 it does not match the coordinates you draw with. Read UserWidth whenever you compare or combine the page width with drawing coordinates, for example to find the right margin edge, to center a block or to decide when content has to move to the next page.

At the default Resolution of 72, UserWidth equals Width. A page sized by setting Width and Height draws in points whatever the Resolution, and UserWidth then equals Width as well.

 

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