THPDFPage.UserWidth

THPDFPage

 

顶部  上一页  下一页

返回以绘图单位表示的页面宽度,即 1/THotPDF.Resolution 英寸

 

Delphi 语法:

property UserWidth: Single; // read-only

 

C++ 语法:

__property float UserWidth = {read=GetUserWidth};

 

说明

X 坐标、边距、字号以及 TextWidth 和 TextHeight 的返回值都以 1/Resolution 英寸为单位。Width 以点(pt)保存页面宽度,赋值时也接收点,所以当 Resolution 不是 72 时,它与绘制所用坐标对不上。凡是要把页面宽度与绘图坐标比较或混用的场合都读 UserWidth,比如求右边距边界、水平居中一个块,或判断内容何时需要换页

默认 Resolution 72 下 UserWidth 等于 Width。通过设置 Width 和 Height 定尺寸的页面无论 Resolution 是多少都按点绘制,此时 UserWidth 同样等于 Width

 

代码示例

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