DocumentViever: Add Support for Annotations

This commit is contained in:
Jonathan Jenne
2022-06-01 16:33:12 +02:00
parent aeb1b5fce5
commit 6d0a2e3a45
3 changed files with 118 additions and 81 deletions

View File

@@ -1,11 +1,7 @@
Imports System.IO
Imports System.ComponentModel
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports DevExpress
Imports DevExpress.Spreadsheet
Imports DevExpress.XtraRichEdit.Commands
Imports DevExpress.XtraRichEdit
Imports DevExpress.Office.Utils
Imports GdPicture14
Imports DigitalData.Modules.Logging
@@ -30,6 +26,11 @@ Public Class DocumentViewer
Excel
End Enum
Private Enum FileLoadMode
File
Stream
End Enum
Private _ViewerMode As ViewerMode
Private _currentSearchOccurence As Integer = 0
Private _toggleGamma As Boolean = True
@@ -40,10 +41,14 @@ Public Class DocumentViewer
Private _email As Email2
Private _Config As ConfigManager(Of Config)
Private _Annotations As Annotations
Private _AnnotationsPending As Boolean = False
Private _hide_file_info_from_user As Boolean = False
Private _FileStream As Stream
Private _FilePath As String
Private _Fileinfo As FileInfo
Private _FileLoadMode As FileLoadMode = FileLoadMode.File
' List of all created temp files when converting msg files
Private _TempFiles As New List(Of String)
@@ -54,6 +59,11 @@ Public Class DocumentViewer
Public Property FileLoaded As Boolean = False
Public ReadOnly Property AnnotationsSaved As Boolean
Get
Return Not _AnnotationsPending
End Get
End Property
''' <summary>
''' Initialize the Viewer
@@ -72,7 +82,55 @@ Public Class DocumentViewer
_Config = New ConfigManager(Of Config)(pLogConfig, oConfigPath)
End Sub
''' <summary>
''' Load a file from a path and display it
''' </summary>
Public Sub LoadFile(FilePath As String)
FileLoaded = False
If _licenseKey = String.Empty Then
_logger.Warn("License key was not provided. File {0} not loaded.", FilePath)
Exit Sub
End If
If FilePath Is Nothing OrElse FilePath.Trim().Length = 0 Then
_logger.Warn("FilePath was not provided. File not loaded.")
Exit Sub
End If
_FilePath = FilePath
_FileLoadMode = FileLoadMode.File
_Fileinfo = New FileInfo(FilePath)
_logger.Info("Loading File [{0}] from Filesystem", FilePath)
FileLoaded = DoLoadFile(FilePath)
SetViewerMode(_Fileinfo.Extension)
UpdateMainUi()
End Sub
''' <summary>
''' Load a file from a stream and display it
''' </summary>
Public Sub LoadFile(FileName As String, Stream As Stream)
FileLoaded = False
If _licenseKey = String.Empty Then
_logger.Warn("License key was not provided. File [{0}] not loaded.", FileName)
Exit Sub
End If
Dim oExtension As String = FileName.Substring(FileName.LastIndexOf("."))
_FileStream = Stream
_FileLoadMode = FileLoadMode.Stream
_logger.Info("Loading file [{0}] from Stream", FileName)
FileLoaded = DoLoadFile(Stream, oExtension)
SetViewerMode(oExtension)
UpdateMainUi()
End Sub
''' <summary>
''' Terminate Viewer, freeing up resources and deleting temp files
@@ -93,63 +151,42 @@ Public Class DocumentViewer
End Try
End Sub
''' <summary>
''' Load a file and display it
''' </summary>
''' <param name="FilePath"></param>
Public Sub LoadFile(FilePath As String)
FileLoaded = False
If _licenseKey = String.Empty Then
_logger.Warn("License key was not provided. File {0} not loaded.", FilePath)
Exit Sub
End If
If FilePath Is Nothing OrElse FilePath.Trim().Length = 0 Then
_logger.Warn("FilePath was not provided. File not loaded.")
Exit Sub
End If
_logger.Info("Loading File {0}", FilePath)
FileLoaded = DoLoadFile(FilePath)
_FilePath = FilePath
_Fileinfo = New FileInfo(FilePath)
SetViewerMode(_Fileinfo.Extension)
UpdateMainUi()
End Sub
Public Sub LoadFile(FileName As String, Stream As Stream)
FileLoaded = False
If _licenseKey = String.Empty Then
_logger.Warn("License key was not provided. File [{0}] not loaded.", FileName)
Exit Sub
End If
Dim oExtension As String = FileName.Substring(FileName.LastIndexOf("."))
_logger.Info("Loading File [{0}]", FileName)
FileLoaded = DoLoadFile(Stream, oExtension)
SetViewerMode(oExtension)
UpdateMainUi()
End Sub
Public Function AddAnnotation(pText As String) As Boolean
Dim oFontStyle = System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline
GdViewer.AddTextAnnotationInteractive(pText, Color.Black, "Arial", oFontStyle, 12, True, Color.Red, Color.White, 1, 0)
Dim oFontStyle = FontStyle.Regular
Dim oFontColor = Color.Black
Dim oFontFamily = "Arial"
Dim oFontSize = 8
Dim oBorderColor = Color.Red
Dim oBackColor = Color.LightYellow
Dim oOpacity = 1.0F
Dim oRotation = 0.0F
GdViewer.AddTextAnnotationInteractive(pText, oFontColor, oFontFamily, oFontStyle, oFontSize, Fill:=True, oBorderColor, oBackColor, oOpacity, oRotation)
_AnnotationsPending = True
Return True
End Function
Public Sub Save()
If GdViewer.SaveDocumentToPDF(_FilePath) = GdPictureStatus.OK Then
_logger.Debug("PDF Successfully saved")
Public Function Save() As Boolean
Dim oSaveResult As GdPictureStatus = GdPictureStatus.OK
If GdViewer.BurnAnnotationsToPage(True, False) = GdPictureStatus.OK Then
If _FileLoadMode = FileLoadMode.Stream Then
oSaveResult = GdViewer.SaveDocumentToPDF(_FileStream)
Else
oSaveResult = GdViewer.SaveDocumentToPDF(_FilePath)
End If
End If
End Sub
If oSaveResult = GdPictureStatus.OK Then
_AnnotationsPending = False
Return True
Else
Return False
End If
End Function
Public Sub CloseDocument()
Try
@@ -455,12 +492,13 @@ Public Class DocumentViewer
SpreadsheetControl1.Dock = DockStyle.Fill
Case Else
'ToolbarDocumentViewer.Visible = True
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
GdViewer.ForceTemporaryMode = True
GdViewer.AnnotationDropShadow = True
GdViewer.DisplayFromFile(FilePath)
End Select
UpdateMainUi()
@@ -528,13 +566,13 @@ Public Class DocumentViewer
SpreadsheetControl1.Dock = DockStyle.Fill
Case Else
'ToolbarDocumentViewer.Visible = True
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
GdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
GdViewer.ForceTemporaryMode = True
GdViewer.AnnotationDropShadow = True
GdViewer.DisplayFromStream(Stream)
End Select
UpdateMainUi()