TPDFlibViewer
查看器
说明
本页介绍 PDFlibPas 中属于"查看器"主题的 TPDFlibViewer 控件。API 名称、参数、类名、文件名及字面量与 Delphi 库完全一致
TPDFlibViewer(单元 Lib\PDFlibViewer.pas)是一个 VCL 滚动控件,可在应用程序内显示 PDF 页面。它使用与 TPDFlib 相同的渲染引擎(GDI+、Cairo 或 PDFium,具体取决于附加实例上 SelectRenderer 的设置)
主要成员
Function LoadFromFile(Const FileName, Password: WideString): Integer;
Procedure AttachLibrary(ALib: TPDFlib);
Procedure CloseDocument;
Function PageCount: Integer;
Function GoToPage(NewPage: Integer): Integer;
Function NextPage: Integer;
Function PrevPage: Integer;
Procedure SetZoomPercent(Percent: Double);
Procedure SetZoomMode(Mode: TPDFlibViewerZoomMode);
Procedure SetDisplayMode(Mode: TPDFlibViewerDisplayMode);
Procedure SetCacheLimit(MegaBytes: Integer);
Procedure RefreshPage;
Function LinkActionAtPagePoint(APage: Integer; XPos, YPos: Double; Out Info: TPDFlibActionInfo): Integer;
Function GetTextInRegion(APage: Integer; XPos, YPos, RWidth, RHeight: Double): WideString;
Function CopySelectedText: Integer;
Property SelectedText: WideString;
Property Page: Integer;
Property DisplayMode: TPDFlibViewerDisplayMode;
Property OnPageChange: TPDFlibViewerPageChange;
Property OnLinkClick: TPDFlibViewerLinkClick;备注
LoadFromFile 通过控件自身的 TPDFlib 实例打开文档;AttachLibrary 则显示由调用方自行管理的实例中的选定文档(所有权归调用方保留)。缩放模式分为固定百分比(zmPercent,通过 SetZoomPercent 设置)、适应宽度(zmFitWidth,默认)和适应页面(zmFitPage);适应模式会在控件大小改变时自动重新计算。页面导航会夹紧到文档页面范围,仅在可见页面真正切换时才触发 OnPageChange。SetDisplayMode 可在单页显示模式(dmSinglePage,默认)和连续垂直滚动浏览整个文档(dmContinuous)之间切换,连续模式下只有视口中可见的页面才会被渲染,当前页随滚动位置自动更新。已渲染的页面保存在最近最少使用(LRU)位图缓存中(默认 128 MB,可通过 SetCacheLimit 调整),因此向上滚动不会重新渲染。鼠标滚轮用于垂直滚动;PageUp/PageDown、方向键、Home 和 End 用于导航。相邻页面会在后台线程中预渲染,确保翻页即时响应。点击链接注释会触发 OnLinkClick 事件,并附带页面编号及类型化动作摘要(TPDFlibActionInfo:网址、文档目标、命名动作等);LinkActionAtPagePoint 则直接提供命中测试,坐标系与 GetAnnotRectEx 报告的用户空间一致。按住鼠标左键拖动可选择文本(在链接上点击则触发链接);Ctrl+C 或 CopySelectedText 复制所选内容,GetTextInRegion 以编程方式执行相同的区域查找。配套控件 TPDFlibOutlineViewer 可在查看器旁边显示文档书签树:调用其 AttachViewer 方法并传入查看器实例后,点击书签即可导航到目标页面。TPDFlibSearchPanel 以相同方式附加:RunSearch 可列出文档中每处命中结果及其页面和匹配文本,点击结果即可跳转到对应页面。TPDFlibThumbnailBar 则以懒加载方式渲染每页缩略图;点击缩略图即可导航到该页。安装设计时包 Package\PDFlibViewerPkg.dpk 后,即可在设计时通过 losLab PDF 面板页将该控件拖放到窗体上