TPdfView
Unit
PDFium
Description
Use TPdfView component to view PDF pages. TPdfView inherits from TScrollingWinControl and provides scrolling, zooming, and page navigation.
Types
type TPdfDisplayMode = (dmSingleContinuous, dmTwoPageContinuous);
Determines how the PDF document pages are displayed.
- dmSingleContinuous - Display pages continuously in a single column
- dmTwoPageContinuous - Display pages continuously in two columns
For other types (TBookmark, TLinkAnnotation, TPdfAnnotation, TPdfImage, TRenderOption, TRotation, TSearchOption, TWebLink, etc.), see TPdf.
Published Properties
property About: string; // read only
Version, copyright, and contact information.
property Active: Boolean; // default False
Opens or closes the selected PDF page.
property Align;
Determines how the control aligns within its container.
property Anchors;
Specifies how the control is anchored to its parent.
property Color;
Specifies the background color of the control.
property Constraints;
Specifies the size constraints for the control.
property CurrentCharIndex: Integer; // default 0
Stores an application-selected character index. Indexed font properties do not depend on this value.
property DisplayMode: TPdfDisplayMode; // default dmSingleContinuous
How pages are displayed (single column or two columns).
property Enabled;
Controls whether the control responds to mouse, keyboard, and timer events.
property Options: TRenderOptions; // default [reLcd]
Rendering options. See TRenderOptions type for further details.
property PageNumber: Integer; // default 1
Currently selected page. PageNumber value has to be 1 to PageCount.
property Pdf: TPdf;
Specifies the PDF document to be displayed.
property Rotation: TRotation; // default ro0
The rotation of PDF page. See TRotation type for further details.
property Zoom: Double;
Zoom factor for the PDF page view.
property PopupMenu;
Identifies the pop-up menu associated with the control.
property ShowHint;
Determines whether the control shows a Help Hint when the mouse pointer rests momentarily on the control.
property TabOrder;
Indicates the position of the control in its parent's tab order.
property TabStop;
Determines if the user can tab to a control.
property Visible;
Determines whether the component appears onscreen.
Public Properties
property ActualSizeZoom[PageNumber: Integer]: Double; // read only
Returns the actual size zoom factor for a specific page.
property Annotation[Index: Integer]: TPdfAnnotation;
Retrieves or sets the specified annotation in the PDF page. The index value has to be from 0 to AnnotationCount - 1.
property AnnotationCount: Integer; // read only
The number of annotations in the PDF page.
property Bitmap[Index: Integer]: TBitmap; // read only
Bitmap data of the specified PDF image object. The index value has to be from 0 to BitmapCount - 1.
property BitmapCount: Integer; // read only
Number of PDF image objects inside the PDF page.
property Canvas: TCanvas; // read only
Provides access to the canvas of the PDF view control.
property Character[Index: Integer]: WideChar; // read only
Returns the specified character in a page. The index value has to be from 0 to CharacterCount - 1.
property CharacterAngle[Index: Integer]: Single; // read only
Returns the rotation angle in radians for the specified character. The index value has to be from 0 to CharacterCount - 1.
property CharacterCount: Integer; // read only
Number of characters in a page.
property CharacterFontSize[Index: Integer]: Double; // read only
Returns the font size of the specified character in points. The index value has to be from 0 to CharacterCount - 1.
FontSize[Index]remains available as a backward-compatible alias.
property CharacterFontWeight[Index: Integer]: Integer; // read only
Returns the font weight of the specified character. Typical values are 400 (normal) and 700 (bold). The index value has to be from 0 to CharacterCount - 1.
property CharacterGenerated[Index: Integer]: Boolean; // read only
Returns True if the specified character in a page is generated by PDFium. The index value has to be from 0 to CharacterCount - 1.
property CharacterIsHyphen[Index: Integer]: Boolean; // read only
Returns True if the specified character in a page is a hyphen. The index value has to be from 0 to CharacterCount - 1.
property CharacterMapError[Index: Integer]: Boolean; // read only
Returns True if the specified character in a page has an invalid unicode mapping. The index value has to be from 0 to CharacterCount - 1.
property CharacterOrigin[Index: Integer]: TPoint; // read only
Origin of a particular character in a page (screen coordinates). The index value has to be from 0 to CharacterCount - 1.
property CharacterRectangle[Index: Integer]: TRect; // read only
Bounding box of a particular character in a page (screen coordinates). The index value has to be from 0 to CharacterCount - 1.
property Charcode[Index: Integer]: WideChar; // read only
Returns the specified character code in a page. The index value has to be from 0 to CharacterCount - 1.
property Find: FPDF_SCHHANDLE; // read only
PDF document search handle.
property FontAscent[Index: Integer; FontSize: Single]: Single; // read only
Returns ascent distance for the font used by the specified text object. The index value has to be from 0 to ObjectCount - 1. The FontSize value controls the point-size scaling.
property FontBaseName[Index: Integer]: WString; // read only
Returns the base name of the font used by the specified text object. The base name is typically the font's PostScript name. The index value has to be from 0 to ObjectCount - 1.
property FontData[Index: Integer]: TBytes; // read only
Returns raw font data for the font used by the specified text object. The index value has to be from 0 to ObjectCount - 1.
property FontDescent[Index: Integer; FontSize: Single]: Single; // read only
Returns descent distance for the font used by the specified text object. The index value has to be from 0 to ObjectCount - 1. The FontSize value controls the point-size scaling.
property FontFamilyName[Index: Integer]: WString; // read only
Returns the family name of the font used by the specified text object. The index value has to be from 0 to ObjectCount - 1.
property FontHandle[Index: Integer]: FPDF_FONT; // read only
Returns the low-level PDFium font handle for the specified text object. The index value has to be from 0 to ObjectCount - 1.
property FontIsEmbedded[Index: Integer]: Boolean; // read only
Determines whether the font used by the specified text object is embedded. The index value has to be from 0 to ObjectCount - 1.
property FontItalicAngle[Index: Integer]: Integer; // read only
Returns the italic angle of the font used by the specified text object. Angle is defined as degrees counterclockwise from vertical; it is negative for a font that slopes to the right.
property FontSize[Index: Integer]: Double; // read only
Backward-compatible alias for
CharacterFontSize[Index]. The index value has to be from 0 to CharacterCount - 1.
property FontWeight[Index: Integer]: Integer; // read only
Returns the weight of the font used by the specified text object. Typical values are 400 (normal) and 700 (bold). The index value has to be from 0 to ObjectCount - 1.
See the
Demo\Delphi\FontPropertiesproject for a complete example that maps clicked text to a text object and reads character metrics and font metadata through TPdfView.
property FormField[Index: Integer]: WString;
Content of the specified PDF form field. The index value has to be from 0 to FormFieldCount - 1.
property FormFieldAt[X, Y: Integer]: WString;
Content of the specified PDF form field. X and Y are screen coordinates.
property FormFieldCount: Integer; // read only
Number of form fields inside the PDF page.
property FormFieldInfo[Index: Integer]: TPdfFormFieldInfo; // read only
Information about the specified PDF form field. The index value has to be from 0 to FormFieldCount - 1.
property FormFieldInfoAt[X, Y: Integer]: TPdfFormFieldInfo; // read only
Information about the specified PDF form field. X and Y are screen coordinates.
property HasFormFieldAt[X, Y: Integer]: Boolean; // read only
Determines whether a form field is located at given location. X and Y are screen coordinates.
property Image[Index: Integer]: TPdfImage; // read only
Size in pixels and data of the specified PDF image object. The index value has to be from 0 to ImageCount - 1.
property ImageCount: Integer; // read only
Number of PDF image objects inside the PDF page.
property LinkAnnotation[PageNumber, Index: Integer]: TLinkAnnotation; // read only
Annotation data for the selected link annotation. The index value has to be from 0 to LinkAnnotationCount - 1.
property LinkAnnotationCount[PageNumber: Integer]: Integer; // read only
Number of link annotations in the specified PDF page.
property ObjectBitmap[Index: Integer]: TBitmap; // read only
Bitmap rasterisation of the specified PDF object or nil if the specific PDF object isn't an image object. The index value has to be from 0 to ObjectCount - 1.
property ObjectBounds[Index: Integer]: TPdfRectangle; // read only
Boundaries of the specified PDF object. The index value has to be from 0 to ObjectCount - 1.
property ObjectCount: Integer; // read only
Number of PDF objects inside the PDF page.
property ObjectHandle[Index: Integer]: Pointer; // read only
Handle of the specified PDF object. The index value has to be from 0 to ObjectCount - 1.
property ObjectTransparent[Index: Integer]: Boolean; // read only
Determines whether the specified PDF object contains transparency. The index value has to be from 0 to ObjectCount - 1.
property ObjectType[Index: Integer]: TObjectType; // read only
Type of the specified PDF object. The index value has to be from 0 to ObjectCount - 1.
property Page: FPDF_PAGE; // read only
PDF document page handle.
property PageBounds: TPdfRectangle; // read only
The bounding box of the page. This is the intersection between its media box and crop box.
property PageCount: Integer; // read only
Total number of pages in a document.
property PageHeight: Double; // read only
Page height (excluding non-displayable area) measured in points. One point is 1/72 inch.
property PageHeightZoom[PageNumber: Integer]: Double; // read only
Returns the zoomed page height.
property PageLabel: WString; // read only
Page label.
property PageRotation: TRotation;
The initial PDF page rotation. The PDF page rotation is rotated clockwise.
property PageWidth: Double; // read only
Page width (excluding non-displayable area) measured in points. One point is 1/72 inch.
property PageWidthZoom[PageNumber: Integer]: Double; // read only
Returns the zoomed page width.
property PageZoom[PageNumber: Integer]: Double; // read only
Returns the zoom factor for a specific page.
property Rectangle[Index: Integer]: TRect; // read only
Get a rectangular area of the selected rectangle from the result generated by the RectangleCount function. The index value has to be from 0 to RectangleCount - 1.
property TextPage: FPDF_TEXTPAGE; // read only
PDF document page text handle.
property Thumbnail: TBitmap; // read only
Page thumbnail or nil if thumbnail isn't available. Returned bitmap has to be manually released.
property Transparent: Boolean; // read only
Check whether the content of specified PDF page contains transparency.
property WebLink[PageNumber, Index: Integer]: TWebLink; // read only
URL information and boundaries for the selected web link. The index value has to be from 0 to WebLinkCount - 1.
property WebLinkCount[PageNumber: Integer]: Integer; // read only
Number of detected web links in the specified page.
property WindowHandle: HWND; // read only
Provides access to the underlying Windows handle of the control.
Methods
function AddJpegImage(JpegImage: TStream; X, Y, Width, Height: Integer): Boolean;
Add JPEG image to the current PDF page using the specified coordinates.
procedure AddPicture(Picture: TPicture; X, Y: Integer);
Add picture to the current PDF page using the specified coordinates.
procedure AddPicture(Picture: TPicture; X, Y, Width, Height: Integer);
Add picture to the current PDF page using the specified coordinates and size.
function CharacterIndexAtPos(X, Y: Integer; ToleranceX, ToleranceY: Double): Integer;
Get the index of a character at or nearby a certain position on the page. If there is no character at or nearby the point, return value will be -1. If an error occurs, -3 will be returned.
procedure CreateAnnotation(const Annotation: TPdfAnnotation);
Create a new annotation.
procedure DeleteAnnotation(Index: Integer);
Delete the specified annotation. The index value has to be from 0 to AnnotationCount - 1.
procedure GenerateFormAppearances;
Delegates to the associated
FormField[i]values and beforeFlattenPage. See TPdf.GenerateFormAppearances for full details.
function FlattenPage(nFlag: Integer = FLAT_NORMALDISPLAY): Integer;
Flattens annotations and form widgets on the current page into static page content. Returns
FLATTEN_SUCCESS,FLATTEN_NOTHINGTODO, orFLATTEN_FAIL. CallGenerateFormAppearancesfirst when flattening filled-in form values.
function DeviceToPage(Rectangle: TRect): TPdfRectangle;
Convert the screen coordinate of a rectangle to page coordinate.
function DeviceToPage(X, Y: Integer; out PageX, PageY: Double): Boolean;
Convert the screen coordinate of a point to page coordinate.
function DeviceToPage(X, Y: Integer; var PageNumber: Integer; var PageX, PageY: Double): Boolean;
Convert the screen coordinate of a point to page coordinate and returns the page number.
function FindFirst(const Text: WString; Options: TSearchOptions = []; StartIndex: Integer = 0; DirectionUp: Boolean = True): Integer;
Start a search of the specified text. StartIndex is 0-based, -1 is for end of the page. DirectionUp parameter determines direction of this search operation.
function FindNext: Integer;
Search in the direction from page start to end. Return text position, or -1 if text was not found. Search must be initiated with FindFirst function.
function FindPrevious: Integer;
Search in the direction from page end to start. Return text position, or -1 if text was not found. Search must be initiated with FindFirst function.
function LinkAnnotationAtPos(X, Y: Integer): Integer;
Get the index of a link annotation at a certain position on the page. If there is no annotation link at the point, return value will be -1.
function LinkAnnotationAtPos(X, Y: Integer; out PageNumber: Integer): Integer;
Get the index of a link annotation at a certain position on the page, returning the page number.
function PageToDevice(Rectangle: TPdfRectangle): TRect;
Convert the page coordinate of a rectangle to screen coordinate.
function PageToDevice(PageX, PageY: Double; out X, Y: Integer): Boolean;
Convert the page coordinate of a point to screen coordinate.
procedure PaintSelection(SelectionStart, SelectionEnd: Integer; Mask: TColor);
Paint the selected text area using the specified mask color.
function RectangleCount(StartIndex: Integer = 0; Count: Integer = MaxInt): Integer;
Count number of rectangular areas occupied by a segment of texts. Function automatically merges small character boxes into bigger one if those characters are on the same line and use same font settings.
procedure ReloadPage;
Reload contents of a page.
procedure RenderPage(DeviceContext: HDC; Left, Top, Width, Height: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []);
Render contents of a page to a device (screen, bitmap, or printer).
function RenderPage(Left, Top, Width, Height: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []): TBitmap;
Render contents of a page to a new bitmap. Returned bitmap has to be manually released.
procedure RenderPage(Bitmap: TBitmap; Left, Top, Width, Height: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []);
Render contents of a page to an existing bitmap.
function RenderTile(Left, Top, Width, Height, PageWidth, PageHeight: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []): TBitmap;
Render rectangular area of a page to a new bitmap. Returned bitmap has to be manually released.
procedure RenderTile(Bitmap: TBitmap; Left, Top, Width, Height, PageWidth, PageHeight: Integer; Rotation: TRotation = ro0; Options: TRenderOptions = []);
Render rectangular area of a page to an existing bitmap.
function Text(StartIndex: Integer = 0; Count: Integer = MaxInt): WString;
Extract text string from the page. StartIndex and Count parameters determine characters to be extracted. StartIndex parameter is 0-based.
function TextInRectangle(Left, Top, Right, Bottom: Integer): WString;
Extract text within a rectangular boundary on the page.
function TextInRectangle(Rectangle: TRect): WString;
Extract text within a rectangular boundary on the page.
procedure UpdatePage;
Generate PDF page content of modified PDF page. Without calling this method, the changed PDF information will be lost.
function WebLinkAtPos(X, Y: Integer): Integer;
Get the index of a web link at a certain position on the page. If there is no web link at the point, return value will be -1.
function WebLinkAtPos(X, Y: Integer; out PageNumber: Integer): Integer;
Get the index of a web link at a certain position on the page, returning the page number.
Events
property OnClick: TNotifyEvent;
Occurs when the user clicks the control.
property OnDblClick: TNotifyEvent;
Occurs when the user double-clicks the control.
property OnKeyDown: TKeyEvent;
Occurs when a key is pressed while the control has focus.
property OnKeyPress: TKeyPressEvent;
Occurs when a key is pressed while the control has focus.
property OnKeyUp: TKeyEvent;
Occurs when a key is released while the control has focus.
property OnMouseDown: TMouseEvent;
Occurs when the user presses a mouse button with the mouse pointer over the control.
property OnMouseMove: TMouseMoveEvent;
Occurs when the user moves the mouse over the control.
property OnMouseUp: TMouseEvent;
Occurs when the user releases a mouse button over the control.
property OnMouseWheel: TMouseWheelEvent;
Occurs when the mouse wheel is rotated.
property OnPageChange: TNotifyEvent;
Write OnPageChange event handler to take specific actions when the current PDF page was changed.
property OnPageNumberChanged: TNotifyEvent;
Write OnPageNumberChanged event handler to take specific actions when the PageNumber property is changed.
property OnPaint: TNotifyEvent;
Occurs when the control is redrawn. Write an event handler for OnPaint to change the way the control renders itself.
property OnResize: TNotifyEvent;
Occurs when the control is resized.