Back to Devexpress

PdfHitTestResult.ContentType Property

wpf-devexpress-dot-xpf-dot-pdfviewer-dot-pdfhittestresult-96b2f137.md

latest7.4 KB
Original Source

PdfHitTestResult.ContentType Property

Indicates the type of the content corresponding to a hit point.

Namespace : DevExpress.Xpf.PdfViewer

Assembly : DevExpress.Xpf.PdfViewer.v25.2.dll

NuGet Package : DevExpress.Wpf.PdfViewer

Declaration

csharp
public PdfDocumentContentType ContentType { get; }
vb
Public ReadOnly Property ContentType As PdfDocumentContentType

Property Value

TypeDescription
PdfDocumentContentType

A PdfDocumentContentType enumeration value.

|

Available values:

NameDescription
None

The PDF content is not defined.

| | Text |

The PDF content is text.

| | Image |

The PDF content is an image.

| | Annotation |

The PDF content is an annotation.

|

Example

View Example: https://github.com/DevExpress-Examples/how-to-determine-the-page-content-type-under-the-mouse-pointer

This example illustrates how to use the PdfViewerControl.HitTest method to determine the type of the page content under the mouse pointer.

This method returns a PdfHitTestResult instance with information about the page content type (text, an image or annotation). You can get the page content type using the PdfHitTestResult.ContentType property and the page content selection status using the PdfHitTestResult.IsSelected property.

In this example, the retrieved information is shown on the Content Type ribbon page group.

Call the PdfViewerControl.HitTest method in the PdfViewerControl.MouseMove event handler to perform hit testing.

csharp
using DevExpress.Pdf;
using DevExpress.Xpf.PdfViewer;
using System.Windows;
using System.Windows.Input;

namespace DetermineContentType {

    public partial class MainWindow : Window {

        public MainWindow() {
            InitializeComponent();
            viewer.OpenDocument("..\\..\\demo.pdf");
        }

        private void viewer_MouseMove(object sender, MouseEventArgs e) {

            PdfHitTestResult result = viewer.HitTest(e.GetPosition(viewer));
            string contentTypeText = result.IsSelected ? "Selected " : "Unselected ";

            switch (result.ContentType) {
                case PdfDocumentContentType.Text:
                contentTypeText = contentTypeText + "Text";
                break;
                case PdfDocumentContentType.Image:
                contentTypeText = contentTypeText + " Image";
                break;
                case PdfDocumentContentType.Annotation:
                contentTypeText = contentTypeText + "Annotation";
                break;
                default:
                contentTypeText = "The content is empty";
                break;
            }
            barButtonItem.Content = contentTypeText;
        }
    }
}
vb
Imports DevExpress.Pdf
Imports DevExpress.Xpf.PdfViewer
Imports System.Windows
Imports System.Windows.Input

Namespace DetermineContentType

    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
            viewer.OpenDocument("..\..\demo.pdf")
        End Sub

        Private Sub viewer_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)

            Dim result As PdfHitTestResult = viewer.HitTest(e.GetPosition(viewer))
            Dim contentTypeText As String = If(result.IsSelected, "Selected ", "Unselected ")

            Select Case result.ContentType
                Case PdfDocumentContentType.Text
                contentTypeText = contentTypeText & "Text"
                Case PdfDocumentContentType.Image
                contentTypeText = contentTypeText & " Image"
                Case PdfDocumentContentType.Annotation
                contentTypeText = contentTypeText & "Annotation"
                Case Else
                contentTypeText = "The content is empty"
            End Select
            barButtonItem.Content = contentTypeText
        End Sub
    End Class
End Namespace
xml
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
        xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
        xmlns:local="clr-namespace:DetermineContentType"
        xmlns:dxpdf="http://schemas.devexpress.com/winfx/2008/xaml/pdf" x:Class="DetermineContentType.MainWindow"
        mc:Ignorable="d"
        Title="PDF Viewer" Height="350" Width="525">
    <Grid>
        <dxpdf:PdfViewerControl x:Name="viewer" MouseMove="viewer_MouseMove" >
            <dxpdf:PdfViewerControl.CommandProvider>
                <dxpdf:PdfCommandProvider>
                    <dxpdf:PdfCommandProvider.RibbonActions>
                        <dxr:InsertRibbonPageGroupAction PageName="{x:Static dxpdf:DefaultPdfBarManagerItemNames.MainRibbonPage}" Index="4">
                            <dxr:RibbonPageGroup Caption="Content Type">
                                <dxb:BarButtonItem x:Name="barButtonItem"/>
                            </dxr:RibbonPageGroup>
                        </dxr:InsertRibbonPageGroupAction>
                    </dxpdf:PdfCommandProvider.RibbonActions>
                </dxpdf:PdfCommandProvider>
            </dxpdf:PdfViewerControl.CommandProvider>
        </dxpdf:PdfViewerControl>
    </Grid>
</Window>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ContentType property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-determine-the-page-content-type-under-the-mouse-pointer/CS/DetermineContentType/MainWindow.xaml.cs#L20

csharp
switch (result.ContentType) {
    case PdfDocumentContentType.Text:

See Also

PdfHitTestResult Class

PdfHitTestResult Members

DevExpress.Xpf.PdfViewer Namespace