How to: Determine the PDF Content Type Corresponding to a Specific Point in a Document

  • 2 minutes to read

This example illustrates how to determine the type of the PDF content corresponding to the point that is being clicked.

using System;
using System.Windows.Forms;
using DevExpress.Pdf;
// ...
        private void Form1_Load(object sender, EventArgs e) {
            this.pdfViewer.LoadDocument(@"..\..\Demo.pdf");
            this.pdfViewer.ZoomMode = DevExpress.XtraPdfViewer.PdfZoomMode.FitToWidth;
        }

        private void pdfViewer_MouseMove(object sender, MouseEventArgs e) {
            PdfDocumentContent content = pdfViewer.GetContentInfo(e.Location);
            if(content != null) {
                string contentTypeText = content.IsSelected ? "Selected " : "Unselected ";
                switch(content.ContentType) {
                    case PdfDocumentContentType.Text:
                        contentTypeText = contentTypeText + "text";
                        break;
                    case PdfDocumentContentType.Image:
                        contentTypeText = contentTypeText + "image";
                        break;
                    default:
                        contentTypeText = "The content is empty";
                        break;
                }
                bsiContentType.Caption = contentTypeText;
            }
        }