PDFiumPas 文件

DeviceToPage 方法

元件: TPdf  ·  單元: PDFium
將點的螢幕座標轉換為頁面座標

Syntax

function DeviceToPage(X, Y, Left, Top, Width, Height: Integer; Rotation: TRotation; out PageX, PageY: Double): Boolean;

X, YInteger。要轉換之點的裝置空間座標(螢幕像素,原點在左上角)
Left, Top, Width, HeightInteger。傳遞給對應 RenderPage 呼叫的算繪矩形
RotationTRotation。算繪時使用的頁面旋轉。必須與傳遞給 RenderPage 的值一致
PageX, PageYDouble。接收轉換後 PDF 使用者空間座標的輸出參數(原點在左下角,單位為點)

Return Value

轉換成功時傳回 True,失敗時(例如未載入任何頁面)傳回 False

Description

將點從裝置空間(螢幕像素)轉換為 PDF 使用者空間(點)。當需要把滑鼠在算繪後頁面上的點擊位置換算回 PDF 頁面上的對應位置時,請使用此方法

PDF 使用者空間的原點位於頁面左下角,Y 軸朝上。裝置空間的原點位於算繪矩形左上角,Y 軸朝下

LeftTopWidthHeightRotation 參數必須與產生被點擊影像的 RenderPage 呼叫所傳入的值完全一致

Example

// Translate a mouse click on the painted page to PDF coordinates
procedure TForm1.PdfPanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  PageX, PageY: Double;
begin
  if Pdf.DeviceToPage(X, Y, 0, 0, PdfPanel.Width, PdfPanel.Height,
    ro0, PageX, PageY) then
    StatusBar1.SimpleText := Format('Page pos: %.1f, %.1f pt', [PageX, PageY]);
end;

See Also

PageToDevice, RenderPage, PageWidth, PageHeight