DocumentViewer handling inconsistent docxfiles
This commit is contained in:
parent
3e2287c6b5
commit
8a61aa208d
@ -60,6 +60,7 @@ Public Class DocumentViewer
|
||||
Private _FilePath As String
|
||||
Private _FileInfo As FileInfo
|
||||
Private _FileLoadMode As FileLoadMode = FileLoadMode.File
|
||||
Private _ViewOverride As String = ""
|
||||
|
||||
' List of all created temp files when converting msg files
|
||||
Private _TempFiles As New List(Of String)
|
||||
@ -141,9 +142,8 @@ Public Class DocumentViewer
|
||||
_FileInfo = New FileInfo(FilePath)
|
||||
|
||||
_logger.Info("Loading file [{0}] from Filesystem", FilePath)
|
||||
FileLoaded = DoLoadFile(FilePath)
|
||||
|
||||
SetViewerMode(_FileInfo.Extension)
|
||||
FileLoaded = DoLoadFile(FilePath)
|
||||
UpdateMainUi()
|
||||
End Sub
|
||||
|
||||
@ -304,12 +304,10 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub btnPreviousPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonPrevPage.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.DisplayPreviousPage()
|
||||
End Sub
|
||||
|
||||
Private Sub btnNextPage_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonNextPage.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.DisplayNextPage()
|
||||
End Sub
|
||||
|
||||
@ -339,12 +337,10 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub btnZoomOut_Click(sender As Object, e As EventArgs) Handles buttonZoomOut.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomOUT()
|
||||
End Sub
|
||||
|
||||
Private Sub btnZoomIn_Click(sender As Object, e As EventArgs) Handles buttonZoomIn.ItemClick
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomIN()
|
||||
End Sub
|
||||
|
||||
@ -439,14 +435,18 @@ Public Class DocumentViewer
|
||||
End Sub
|
||||
|
||||
Private Sub SetViewerMode(Extension As String)
|
||||
If _ViewOverride = "Richtext" Then
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
Else
|
||||
Select Case Extension.ToUpper
|
||||
Case "CSV"
|
||||
_ViewerMode = ViewerMode.Excel
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
_ViewerMode = ViewerMode.RichText
|
||||
'Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
' _ViewerMode = ViewerMode.RichText
|
||||
Case Else
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
End Select
|
||||
End If
|
||||
End Sub
|
||||
Private Sub FreeFile()
|
||||
Try
|
||||
@ -466,7 +466,7 @@ Public Class DocumentViewer
|
||||
_logger.Warn($"Unexpected error in FreeFile: {ex.Message}")
|
||||
End Try
|
||||
End Sub
|
||||
Private Function DoLoadFile(FilePath As String) As Boolean
|
||||
Private Function DoLoadFile(FilePath As String, Optional ViewOverride As String = "") As Boolean
|
||||
Try
|
||||
Dim oFileInfo = New FileInfo(FilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension.ToUpper
|
||||
@ -479,6 +479,17 @@ Public Class DocumentViewer
|
||||
SpreadsheetControl1.Dock = DockStyle.None
|
||||
RichEditControl1.Dock = DockStyle.None
|
||||
|
||||
If ViewOverride = "Richtext" Then
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
_ViewOverride = "Richtext"
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
MsgBox("This docx-file contains a generic error and will be displayed in a reduced viewer." & vbNewLine &
|
||||
"Please try to open the file in WORD", MsgBoxStyle.Exclamation, "Error opening docx-file")
|
||||
Else
|
||||
_ViewOverride = ""
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".CSV"
|
||||
Dim oFormat = GetSpreadsheetFormat(oExtension)
|
||||
@ -490,15 +501,16 @@ Public Class DocumentViewer
|
||||
SpreadsheetControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
SpreadsheetControl1.Dock = DockStyle.Fill
|
||||
Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
RichEditControl1.Visible = True
|
||||
GdViewer.Visible = False
|
||||
RichEditControl1.Dock = DockStyle.Fill
|
||||
'Case ".EML", ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
|
||||
' RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(oExtension))
|
||||
|
||||
' RichEditControl1.Visible = True
|
||||
' GdViewer.Visible = False
|
||||
' RichEditControl1.Dock = DockStyle.Fill
|
||||
Case Else
|
||||
Select Case oExtension.ToUpper
|
||||
Case ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT", ".DWG"
|
||||
Case ".EML", ".DOC", ".DOCX", ".XLS", ".XLSX", ".ODT", ".RTF", ".TXT"
|
||||
GdViewer.ForceTemporaryMode = False
|
||||
End Select
|
||||
|
||||
@ -511,11 +523,17 @@ Public Class DocumentViewer
|
||||
GdViewer.AnnotationDropShadow = True
|
||||
GdViewer.BackColor = Color.White
|
||||
|
||||
If GdViewer.DisplayFromFile(FilePath) <> GdPictureStatus.OK Then
|
||||
|
||||
Dim oGDPState As GdPicture14.GdPictureStatus = GdViewer.DisplayFromFile(FilePath)
|
||||
If oGDPState <> GdPictureStatus.OK Then
|
||||
_logger.Warn($"GdPictureStatus is [{oGDPState}]")
|
||||
If oExtension.ToUpper = ".DOCX" And oGDPState = GdPictureStatus.GenericError Then
|
||||
DoLoadFile(FilePath, "Richtext")
|
||||
Else
|
||||
Dim oFileName = IO.Path.GetFileName(FilePath)
|
||||
lbFileNotLoaded.Text = String.Format("Datei konnte nicht geladen werden:{0}{1}", vbCrLf, oFileName)
|
||||
lbFileNotLoaded.Visible = True
|
||||
End If
|
||||
|
||||
Else
|
||||
If GdViewer.Visible = False Then
|
||||
GdViewer.Visible = True
|
||||
@ -523,8 +541,11 @@ Public Class DocumentViewer
|
||||
End If
|
||||
|
||||
End Select
|
||||
End If
|
||||
If _ViewOverride = "Richtext" Then
|
||||
_ViewerMode = ViewerMode.Richtext
|
||||
End If
|
||||
|
||||
UpdateMainUi()
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@ -534,12 +555,10 @@ Public Class DocumentViewer
|
||||
End Function
|
||||
|
||||
Private Sub FitToPage()
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
|
||||
End Sub
|
||||
|
||||
Private Sub FitToWidth()
|
||||
_ViewerMode = ViewerMode.GDPicture
|
||||
GdViewer.ZoomMode = ViewerZoomMode.ZoomModeWidthViewer
|
||||
End Sub
|
||||
|
||||
@ -677,9 +696,8 @@ Public Class DocumentViewer
|
||||
btnSearch2.Visibility = ToVisibility(False)
|
||||
btnNextHighlight.Visibility = ToVisibility(False)
|
||||
btnPrevHighlight.Visibility = ToVisibility(False)
|
||||
|
||||
|
||||
|
||||
Case Else
|
||||
ToolbarDocumentViewer.Visible = False
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.2.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.2.0.0")>
|
||||
<Assembly: AssemblyVersion("2.3.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.3.0.0")>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user