VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
PDF: Редактирование PDF аннотаций PDF документа в WPF
В этом разделе
Класс WpfPdfAnnotationTool позволяет редактировать аннотации к PDF страницам в WPF просмотрщике изображений. Класс может редактировать PDF аннотации в двух режимах: 'Markup' и 'Edit'.

В режиме 'Markup' класс WpfPdfAnnotationTool:
В режиме 'Edit' класс WpfPdfAnnotationTool:
Процесс визуального построения аннотации выполняется с помощью метода WpfPdfAnnotationTool.AddAndBuildAnnotation.

Вот C#/VB.NET код, который демонстрирует, как создать визуальный инструмент для отображения и взаимодействия с аннотациями и полями интерактивной PDF формы:
/// <summary>
/// Creates the PDF annotation tool with JavaScript support.
/// </summary>
/// <param name="viewer">The image viewer.</param>
public static Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool CreatePdfAnnotationToolWithJavaScriptSupport(
    Vintasoft.Imaging.Wpf.UI.WpfImageViewer viewer)
{
    // create PDF JavaScript application
    Vintasoft.Imaging.Pdf.Wpf.UI.JavaScript.WpfPdfJsApp jsApp = 
        new Vintasoft.Imaging.Pdf.Wpf.UI.JavaScript.WpfPdfJsApp();
    // add PDF documents, which are associated with images in viewer,
    // to the document set of PDF JavaScript application
    jsApp.RegisterImageViewer(viewer);
    // create PdfJavaScriptActionExecutor for PDF JavaScript application
    jsApp.ActionExecutor = new Vintasoft.Imaging.Pdf.JavaScript.PdfJavaScriptActionExecutor(
        jsApp, new Vintasoft.Imaging.Pdf.JavaScriptApi.PdfJsConsole());

    // create PdfAnnotationTool
    Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool annotationTool = 
        new Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool(jsApp, true);
    annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup;

    // create an application action executor
    Vintasoft.Imaging.Pdf.PdfActionCompositeExecutor applicationActionExecutor = 
        new Vintasoft.Imaging.Pdf.PdfActionCompositeExecutor();
    // add executor for PdfJavaScriptAction to the application action executor
    applicationActionExecutor.Items.Add(jsApp.ActionExecutor);
    // add executor for PdfGotoAction to the application action executor
    applicationActionExecutor.Items.Add(new Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfGotoActionExecutor(viewer));
    // add executor for PdfNamedAction to the application action executor
    applicationActionExecutor.Items.Add(new Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfNamedActionExecutor(viewer));
    // add executor for PdfResetFormAction to the application action executor
    applicationActionExecutor.Items.Add(
        new Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationToolResetFormActionExecutor(annotationTool));
    // add executor for PdfAnnotationHideAction to the application action executor
    applicationActionExecutor.Items.Add(
        new Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationToolAnnotationHideActionExecutor(annotationTool));
    // add executor for PdfUriAction to the application action executor,
    // executor is located in WpfPdfDemosCommonCode
    //applicationActionExecutor.Items.Add(new PdfUriActionExecutor());
    // add executor for PdfLaunchAction to the application action executor,
    // executor is located in WpfPdfDemosCommonCode
    //applicationActionExecutor.Items.Add(new PdfLaunchActionExecutor());
    // add executor for PdfSubmitFormAction to the application action executor,
    // executor is located in WpfPdfDemosCommonCode
    //applicationActionExecutor.Items.Add(new PdfSubmitActionExecutor(viewer));
    // add the default executor (for PdfResetFormAction and PdfAnnotationHideAction)
    // to the application action executor
    applicationActionExecutor.Items.Add(new Vintasoft.Imaging.Pdf.PdfActionExecutor());

    // set the application action executor as action executor of PDF annotation tool
    annotationTool.ActionExecutor = applicationActionExecutor;

    // create a document-level actions executor
    Vintasoft.Imaging.Pdf.PdfDocumentLevelActionsExecutor documentLevelActionsExecutor =
       new Vintasoft.Imaging.Pdf.PdfDocumentLevelActionsExecutor(jsApp);
    // set the application action executor as action executor of the document-level actions executor
    documentLevelActionsExecutor.ActionExecutor = applicationActionExecutor;

    return annotationTool;
}
''' <summary>
''' Creates the PDF annotation tool with JavaScript support.
''' </summary>
''' <param name="viewer">The image viewer.</param>
Public Shared Function CreatePdfAnnotationToolWithJavaScriptSupport(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer) As Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool
    ' create PDF JavaScript application
    Dim jsApp As New Vintasoft.Imaging.Pdf.Wpf.UI.JavaScript.WpfPdfJsApp()
    ' add PDF documents, which are associated with images in viewer,
    ' to the document set of PDF JavaScript application
    jsApp.RegisterImageViewer(viewer)
    ' create PdfJavaScriptActionExecutor for PDF JavaScript application
    jsApp.ActionExecutor = New Vintasoft.Imaging.Pdf.JavaScript.PdfJavaScriptActionExecutor(jsApp, New Vintasoft.Imaging.Pdf.JavaScriptApi.PdfJsConsole())

    ' create PdfAnnotationTool
    Dim annotationTool As New Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool(jsApp, True)
    annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup

    ' create an application action executor
    Dim applicationActionExecutor As New Vintasoft.Imaging.Pdf.PdfActionCompositeExecutor()
    ' add executor for PdfJavaScriptAction to the application action executor
    applicationActionExecutor.Items.Add(jsApp.ActionExecutor)
    ' add executor for PdfGotoAction to the application action executor
    applicationActionExecutor.Items.Add(New Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfGotoActionExecutor(viewer))
    ' add executor for PdfNamedAction to the application action executor
    applicationActionExecutor.Items.Add(New Vintasoft.Imaging.Pdf.Wpf.UI.WpfPdfNamedActionExecutor(viewer))
    ' add executor for PdfResetFormAction to the application action executor
    applicationActionExecutor.Items.Add(New Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationToolResetFormActionExecutor(annotationTool))
    ' add executor for PdfAnnotationHideAction to the application action executor
    applicationActionExecutor.Items.Add(New Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationToolAnnotationHideActionExecutor(annotationTool))
    ' add executor for PdfUriAction to the application action executor,
    ' executor is located in WpfPdfDemosCommonCode
    'applicationActionExecutor.Items.Add(new PdfUriActionExecutor());
    ' add executor for PdfLaunchAction to the application action executor,
    ' executor is located in WpfPdfDemosCommonCode
    'applicationActionExecutor.Items.Add(new PdfLaunchActionExecutor());
    ' add executor for PdfSubmitFormAction to the application action executor,
    ' executor is located in WpfPdfDemosCommonCode
    'applicationActionExecutor.Items.Add(new PdfSubmitActionExecutor(viewer));
    ' add the default executor (for PdfResetFormAction and PdfAnnotationHideAction)
    ' to the application action executor
    applicationActionExecutor.Items.Add(New Vintasoft.Imaging.Pdf.PdfActionExecutor())

    ' set the application action executor as action executor of PDF annotation tool
    annotationTool.ActionExecutor = applicationActionExecutor

    ' create a document-level actions executor
    Dim documentLevelActionsExecutor As New Vintasoft.Imaging.Pdf.PdfDocumentLevelActionsExecutor(jsApp)
    ' set the application action executor as action executor of the document-level actions executor
    documentLevelActionsExecutor.ActionExecutor = applicationActionExecutor

    Return annotationTool
End Function


Вот C#/VB.NET код, который демонстрирует, как начать создание PDF аннотации:
/// <summary>
/// Adds and builds a polyline annotation.
/// </summary>
/// <param name="annotationTool">The PDF annotation tool, which will build an annotation.</param>
public static void AddAndBuildPolylineeAnnotation(
    Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool annotationTool)
{
    Vintasoft.Imaging.Pdf.Tree.PdfPage focusedPage = annotationTool.FocusedPage;
    if (focusedPage == null)
        throw new System.InvalidOperationException();

    // create a PDF annotation
    Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation annotation = 
        new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation(focusedPage);
    annotation.BorderWidth = 5;
    annotation.Color = System.Drawing.Color.Red;
    annotation.InteriorColor = System.Drawing.Color.Green;
    annotation.StartPointLineEndingStyle = 
        Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationLineEndingStyle.ClosedArrow;

    // if tool mode does not allow to build annotation
    if (annotationTool.InteractionMode == Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.None ||
        annotationTool.InteractionMode == Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.View)
        // change the tool mode
        annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup;

    // add and build the annotation
    annotationTool.AddAndBuildAnnotation(annotation);
}
''' <summary>
''' Adds and builds a polyline annotation.
''' </summary>
''' <param name="annotationTool">The PDF annotation tool, which will build an annotation.</param>
Public Shared Sub AddAndBuildPolylineeAnnotation(annotationTool As Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool)
    Dim focusedPage As Vintasoft.Imaging.Pdf.Tree.PdfPage = annotationTool.FocusedPage
    If focusedPage Is Nothing Then
        Throw New System.InvalidOperationException()
    End If

    ' create a PDF annotation
    Dim annotation As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation(focusedPage)
    annotation.BorderWidth = 5
    annotation.Color = System.Drawing.Color.Red
    annotation.InteriorColor = System.Drawing.Color.Green
    annotation.StartPointLineEndingStyle = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationLineEndingStyle.ClosedArrow

    ' if tool mode does not allow to build annotation
    If annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.None OrElse annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.View Then
        ' change the tool mode
        annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup
    End If

    ' add and build the annotation
    annotationTool.AddAndBuildAnnotation(annotation)
End Sub


Вот C#/VB.NET код, который демонстрирует, как переопределить процесс создания PDF аннотации и запустить создание PDF аннотации:
/// <summary>
/// Adds and builds a polyline annotation.
/// </summary>
/// <param name="annotationTool">The PDF annotation tool, which will build an annotation.</param>
public static void AddAndBuildPolylineeAnnotation(
    Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool annotationTool)
{
    Vintasoft.Imaging.Pdf.Tree.PdfPage focusedPage = annotationTool.FocusedPage;
    if (focusedPage == null)
        throw new System.InvalidOperationException();

    // create a PDF annotation
    Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation annotation = 
        new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation(focusedPage);
    annotation.BorderWidth = 5;
    annotation.Color = System.Drawing.Color.Red;
    annotation.InteriorColor = System.Drawing.Color.Green;
    annotation.StartPointLineEndingStyle = 
        Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationLineEndingStyle.ClosedArrow;

    // if tool mode does not allow to build annotation
    if (annotationTool.InteractionMode == Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.None ||
        annotationTool.InteractionMode == Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.View)
        // change the tool mode
        annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup;

    // add and build the annotation
    annotationTool.AddAndBuildAnnotation(annotation);
}
''' <summary>
''' Adds and builds a polyline annotation.
''' </summary>
''' <param name="annotationTool">The PDF annotation tool, which will build an annotation.</param>
Public Shared Sub AddAndBuildPolylineeAnnotation(annotationTool As Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationTool)
    Dim focusedPage As Vintasoft.Imaging.Pdf.Tree.PdfPage = annotationTool.FocusedPage
    If focusedPage Is Nothing Then
        Throw New System.InvalidOperationException()
    End If

    ' create a PDF annotation
    Dim annotation As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfPolylineAnnotation(focusedPage)
    annotation.BorderWidth = 5
    annotation.Color = System.Drawing.Color.Red
    annotation.InteriorColor = System.Drawing.Color.Green
    annotation.StartPointLineEndingStyle = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationLineEndingStyle.ClosedArrow

    ' if tool mode does not allow to build annotation
    If annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.None OrElse annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.View Then
        ' change the tool mode
        annotationTool.InteractionMode = Vintasoft.Imaging.Pdf.Wpf.UI.Annotations.WpfPdfAnnotationInteractionMode.Markup
    End If

    ' add and build the annotation
    annotationTool.AddAndBuildAnnotation(annotation)
End Sub