-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdialogWebBrowser.vb
198 lines (198 loc) · 10 KB
/
dialogWebBrowser.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
Imports System.Windows.Forms
Public Class dialogWebBrowser
''' <summary>
''' PdForms.net - An open source pdf form editor
''' Copyright 2018 NK-INC.COM All Rights reserved.
''' PdForms.net utilizes iTextSharp technologies.
''' Website: www.pdforms.net (source code), www.pdforms.com (about)
''' </summary>
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub textboxURL_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textboxURL.KeyUp
Try
If e.KeyCode = Keys.Enter Then
WebBrowser1.Url = New System.Uri(textboxURL.Text)
End If
Catch ex As Exception
Err.Clear()
End Try
End Sub
Private Sub textboxURL_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles textboxURL.MouseUp
End Sub
Private Sub textboxURL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textboxURL.TextChanged
End Sub
Public Sub New()
InitializeComponent()
End Sub
Public frm As frmMain = Nothing
Public Sub New(ByRef frmMain1 As frmMain)
InitializeComponent()
frm = frmMain1
End Sub
Public Sub LoadURL(ByVal strURL As String)
Try
textboxURL.Text = strURL
WebBrowser1.Url = New System.Uri(textboxURL.Text)
Catch ex As Exception
Err.Clear()
End Try
End Sub
Private Sub dialogWebBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub SaveAs_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAs_Button.Click
Try
WebBrowser1.ShowSaveAsDialog()
Catch ex As Exception
Err.Clear()
End Try
End Sub
Public Function GenerateScreenshot(ByVal url As String) As Bitmap
Return GenerateScreenshot(url, -1, -1)
End Function
Public Function GenerateScreenshotAlternative(ByVal url As String, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim wb As New WebBrowser
Try
wb.ScrollBarsEnabled = False
wb.ScriptErrorsSuppressed = True
Dim strHeaders As String = ""
strHeaders &= "User-Agent: mozilla/5.0 (windows nt 6.1; trident/7.0; rv:11.0) like gecko" & vbCrLf
strHeaders &= "Referer: http://www.google.com/" & vbCrLf
wb.Navigate(url, "_self", Nothing, strHeaders.ToString)
While wb.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
wb.Width = width
wb.Height = height
If width <= 0 Then
wb.Width = wb.Document.Body.ScrollRectangle.Width
End If
If height <= 0 Then
wb.Height = wb.Document.Body.ScrollRectangle.Height
End If
Dim bitmap As New Bitmap(wb.Width, wb.Height)
wb.DrawToBitmap(bitmap, New Rectangle(0, 0, wb.Width, wb.Height))
wb.Dispose()
Return bitmap
Catch ex As Exception
Err.Clear()
End Try
Return Nothing
End Function
Public Function GenerateScreenshot(ByVal url As String, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim wb As New WebBrowser
Try
wb.ScrollBarsEnabled = False
wb.ScriptErrorsSuppressed = True
Dim strHeaders As String = ""
strHeaders &= "User-Agent: mozilla/5.0 (windows nt 6.1; trident/7.0; rv:11.0) like gecko" & vbCrLf
strHeaders &= "Referer: http://www.google.com/" & vbCrLf
wb.Navigate(url, "_self", Nothing, strHeaders.ToString)
While wb.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
wb.Width = width
wb.Height = height
If width <= 0 Then
wb.Width = wb.Document.Body.ScrollRectangle.Width
End If
If height <= 0 Then
wb.Height = wb.Document.Body.ScrollRectangle.Height
End If
Dim img As System.Drawing.Image = New System.Drawing.Bitmap(wb.Width, wb.Height)
Utilities.NativeMethods.GetImage(wb, img, Color.Transparent)
wb.Dispose()
Dim bitmap As New System.Drawing.Bitmap(img, wb.Width, wb.Height)
Return bitmap
Catch ex As Exception
Err.Clear()
End Try
Return Nothing
End Function
Private Sub Print_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print_Button.Click
Try
WebBrowser1.ShowPrintDialog()
Catch ex As Exception
Err.Clear()
End Try
End Sub
Private Sub Import_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Import_Button.Click
Try
If System.IO.File.Exists(WebBrowser1.Url.AbsolutePath.ToString) Then
Dim wb_type As FDFApp.FDFDoc_Class.FDFType = frm.cFDFDoc.Determine_Type(WebBrowser1.Url.AbsolutePath.ToString)
Select Case wb_type
Case FDFApp.FDFDoc_Class.FDFType.PDF, FDFApp.FDFDoc_Class.FDFType.XFA, FDFApp.FDFDoc_Class.FDFType.XPDF
frm.OpenFile(WebBrowser1.Url.AbsolutePath.ToString())
Return
Case FDFApp.FDFDoc_Class.FDFType.FDF, FDFApp.FDFDoc_Class.FDFType.XDP, FDFApp.FDFDoc_Class.FDFType.xFDF, FDFApp.FDFDoc_Class.FDFType.XML
frm.OpenFile(WebBrowser1.Url.AbsolutePath.ToString())
Return
Case Else
Dim dMultipleChoice As New dialogMultiChoice(Me)
dMultipleChoice.lblMessage.Text = "Import HTML page as..."
Dim clsBut As New List(Of dialogMultiChoice.clsButton)
Dim btn As dialogMultiChoice.clsButton
btn = New dialogMultiChoice.clsButton("as HTML", True, DialogResult.OK)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("as Image", True, DialogResult.Yes)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("", False, DialogResult.No)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("Cancel", True, DialogResult.Cancel)
clsBut.Add(btn)
Select Case dMultipleChoice.ShowDialog(frm, "Import HTML page as:", clsBut.ToArray())
Case DialogResult.OK
frm.Convert_ImportURl2HTMLFile(Me.WebBrowser1.Url.AbsolutePath.ToString() & "")
Case DialogResult.Yes
frm.Convert_ImportURl2ImageFile(Me.WebBrowser1.Url.AbsolutePath.ToString() & "")
Case Else
Exit Select
End Select
End Select
ElseIf frm.IsValidUrl(WebBrowser1.Url.AbsoluteUri.ToString) Then
Dim wb_type As FDFApp.FDFDoc_Class.FDFType = frm.cFDFDoc.Determine_Type(WebBrowser1.Url.AbsoluteUri.ToString)
Select Case wb_type
Case FDFApp.FDFDoc_Class.FDFType.PDF, FDFApp.FDFDoc_Class.FDFType.XFA, FDFApp.FDFDoc_Class.FDFType.XPDF
frm.OpenFileFromUrl(WebBrowser1.Url.AbsoluteUri.ToString())
Return
Case FDFApp.FDFDoc_Class.FDFType.FDF, FDFApp.FDFDoc_Class.FDFType.XDP, FDFApp.FDFDoc_Class.FDFType.xFDF, FDFApp.FDFDoc_Class.FDFType.XML
frm.OpenFileFromUrl(WebBrowser1.Url.ToString())
Return
Case Else
Dim dMultipleChoice As New dialogMultiChoice(Me)
dMultipleChoice.lblMessage.Text = "Import HTML page as..."
Dim clsBut As New List(Of dialogMultiChoice.clsButton)
Dim btn As dialogMultiChoice.clsButton
btn = New dialogMultiChoice.clsButton("as HTML", True, DialogResult.OK)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("as Image", True, DialogResult.Yes)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("", False, DialogResult.No)
clsBut.Add(btn)
btn = New dialogMultiChoice.clsButton("Cancel", True, DialogResult.Cancel)
clsBut.Add(btn)
Select Case dMultipleChoice.ShowDialog(frm, "Import HTML page as:", clsBut.ToArray())
Case DialogResult.OK
frm.Convert_ImportURl2HTMLFile(Me.WebBrowser1.Url.AbsolutePath.ToString() & "")
Case DialogResult.Yes
frm.Convert_ImportURl2ImageFile(Me.WebBrowser1.Url.AbsolutePath.ToString() & "")
Case Else
Exit Select
End Select
End Select
End If
Catch ex As Exception
Err.Clear()
Finally
frm.Show()
frm.BringToFront()
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Me.Close()
End Try
End Sub
End Class