Skip to content

Commit

Permalink
fix of missing pdf tool
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Mar 13, 2021
1 parent 117e6ca commit e71eeb6
Showing 1 changed file with 63 additions and 48 deletions.
111 changes: 63 additions & 48 deletions src/mzkit/mzkit/pages/dockWindow/documents/frmHtmlViewer.vb
Original file line number Diff line number Diff line change
@@ -1,64 +1,79 @@
#Region "Microsoft.VisualBasic::cfb956a25f80777b1be73f0a791b5ad8, pages\dockWindow\documents\frmHtmlViewer.vb"

' Author:
'
' xieguigang ([email protected], BioNovoGene Co., LTD.)
'
' Copyright (c) 2018 [email protected], BioNovoGene Co., LTD.
'
'
' MIT License
'
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all
' copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.



' /********************************************************************************/

' Summaries:

' Class frmHtmlViewer
'
' Sub: frmHtmlViewer_Load, LoadHtml, PDF, SavePDFToolStripMenuItem_Click, WebBrowser1_DocumentCompleted
'
' /********************************************************************************/
' Author:
'
' xieguigang ([email protected], BioNovoGene Co., LTD.)
'
' Copyright (c) 2018 [email protected], BioNovoGene Co., LTD.
'
'
' MIT License
'
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all
' copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.



' /********************************************************************************/

' Summaries:

' Class frmHtmlViewer
'
' Sub: frmHtmlViewer_Load, LoadHtml, PDF, SavePDFToolStripMenuItem_Click, WebBrowser1_DocumentCompleted
'
' /********************************************************************************/

#End Region

Imports mzkit.My
Imports WkHtmlToPdf.Arguments

Public Class frmHtmlViewer

Dim url As String

Public Sub PDF(filepath As String)
Dim env As New PdfConvertEnvironment With {
.Debug = False,
.TempFolderPath = App.GetAppSysTempFile,
.Timeout = 60000,
.WkHtmlToPdfPath = $"{App.HOME}/wkhtmltopdf.exe"
}
Dim content As New PdfDocument With {.Url = {WebBrowser1.Url.OriginalString}}
Dim pdfFile As New PdfOutput With {.OutputFilePath = filepath}
Static bin As String = Nothing

If bin.StringEmpty Then
bin = $"{App.HOME}/tools/wkhtmltopdf.exe"

Call WkHtmlToPdf.PdfConvert.ConvertHtmlToPdf(content, pdfFile, env)
If Not bin.FileExists Then
bin = $"{App.HOME}/wkhtmltopdf.exe"
End If
End If

If bin.FileExists Then
Dim env As New PdfConvertEnvironment With {
.Debug = False,
.TempFolderPath = App.GetAppSysTempFile,
.Timeout = 60000,
.WkHtmlToPdfPath = bin
}
Dim content As New PdfDocument With {.Url = {WebBrowser1.Url.OriginalString}}
Dim pdfFile As New PdfOutput With {.OutputFilePath = filepath}

Call WkHtmlToPdf.PdfConvert.ConvertHtmlToPdf(content, pdfFile, env)
Else
Call MyApplication.host.showStatusMessage("'wkhtmltopdf' tool is missing for generate PDF file...", My.Resources.StatusAnnotations_Warning_32xLG_color)
End If
End Sub

Public Sub LoadHtml(url As String)
Expand Down

0 comments on commit e71eeb6

Please sign in to comment.