Класс WpfPdfContentXObjectTool
Визуальный инструмент, позволяющий извлекать, выбирать, преобразовывать, заменять или удалять изображения или формы на PDF странице.
Вот C#/VB.NET код, который демонстрирует, как выделить сфокусированный XObject в PDF документе, загруженном в просмотрщик изображений.
''' <summary>
''' A window that allows to load PDF document into image viewer and
''' highlight focused XObject in PDF document.
''' </summary>
Public Partial Class WindowWithWpfPdfContentXObjectTool
Inherits System.Windows.Window
'...
Private _imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer
Private _contentXObjectTool As Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectTool
Public Sub New()
'...
' create an instance of the WpfPdfContentXObjectTool
_contentXObjectTool = New Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectTool()
' set a pen and brush for image selection
_contentXObjectTool.SelectionImagesBrush = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(32, 0, 0, 255))
_contentXObjectTool.SelectionImagesPen = New System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1)
' set a pen and brush for form selection
_contentXObjectTool.SelectionFormsBrush = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(32, 0, 255, 0))
_contentXObjectTool.SelectionFormsPen = New System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 1)
' subscribe to content XObject tool events
AddHandler _contentXObjectTool.ContentXObjectMouseEnter, New System.EventHandler(Of Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs)(AddressOf ContentXObjectTool_ContentXObjectMouseEnter)
AddHandler _contentXObjectTool.ContentXObjectMouseLeave, New System.EventHandler(Of Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs)(AddressOf ContentXObjectTool_ContentXObjectMouseLeave)
' set the content XObject tool as current tool
_imageViewer.VisualTool = _contentXObjectTool
End Sub
''' <summary>
''' Occurs when the mouse pointer enters the XObject on PDF page.
''' </summary>
Private Sub ContentXObjectTool_ContentXObjectMouseEnter(sender As Object, e As Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs)
' add the focused XObject to the list of focused XObjects
_contentXObjectTool.SelectedXObjects.Add(e.ContentXObject)
End Sub
''' <summary>
''' Occurs when the mouse pointer leaves the XObject on PDF page.
''' </summary>
Private Sub ContentXObjectTool_ContentXObjectMouseLeave(sender As Object, e As Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs)
' remove focused XObject from the list of focused XObjects
_contentXObjectTool.SelectedXObjects.Remove(e.ContentXObject)
End Sub
End Class
/// <summary>
/// A window that allows to load PDF document into image viewer and
/// highlight focused XObject in PDF document.
/// </summary>
public partial class WindowWithWpfPdfContentXObjectTool : System.Windows.Window
{
//...
Vintasoft.Imaging.Wpf.UI.WpfImageViewer _imageViewer;
Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectTool _contentXObjectTool;
public WindowWithWpfPdfContentXObjectTool()
{
//...
// create an instance of the WpfPdfContentXObjectTool
_contentXObjectTool = new Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectTool();
// set a pen and brush for image selection
_contentXObjectTool.SelectionImagesBrush =
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(32, 0, 0, 255));
_contentXObjectTool.SelectionImagesPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
// set a pen and brush for form selection
_contentXObjectTool.SelectionFormsBrush =
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(32, 0, 255, 0));
_contentXObjectTool.SelectionFormsPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Blue, 1);
// subscribe to content XObject tool events
_contentXObjectTool.ContentXObjectMouseEnter +=
new System.EventHandler<Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs>(ContentXObjectTool_ContentXObjectMouseEnter);
_contentXObjectTool.ContentXObjectMouseLeave +=
new System.EventHandler<Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs>(ContentXObjectTool_ContentXObjectMouseLeave);
// set the content XObject tool as current tool
_imageViewer.VisualTool = _contentXObjectTool;
}
/// <summary>
/// Occurs when the mouse pointer enters the XObject on PDF page.
/// </summary>
private void ContentXObjectTool_ContentXObjectMouseEnter(
object sender,
Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs e)
{
// add the focused XObject to the list of focused XObjects
_contentXObjectTool.SelectedXObjects.Add(e.ContentXObject);
}
/// <summary>
/// Occurs when the mouse pointer leaves the XObject on PDF page.
/// </summary>
private void ContentXObjectTool_ContentXObjectMouseLeave(
object sender,
Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfContentXObjectEventArgs e)
{
// remove focused XObject from the list of focused XObjects
_contentXObjectTool.SelectedXObjects.Remove(e.ContentXObject);
}
}
Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5