I got this code in vb.net
Imports RasterEdge.Imaging.Basic.TextSearch
Imports RasterEdge.XDoc.PDF
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Open a document
Dim doc As PDFDocument = New PDFDocument(Application.StartupPath & "/Vertrag.pdf")
'Set the search options
Dim options As RESearchOption = New RESearchOption()
options.IgnoreCase = False
options.WholeWord = False
'Replace "RasterEdge" with "Image"
doc.Replace("#Name", "#Lame", options) <-- Here i get the error
doc.Save(Application.StartupPath & "/testoutput.pdf")
End Sub
End Class
I marked where the System.ArgumentOutOfRangeException error pops up.
All of this uses the RasterEdge dlls to replace a piece of text with soe other piece of text (#Name --> #Lame (just a test))
Do you guys have any ideas?
Related
I want to set a background image of windows form using code. and I am doing so using this code. Code in the form's page load event:
Me.Panel2.BackgroundImage = Image.FromFile(My.Settings.BGimage.ToString)
and code of button's click event.
Dim BGimage As Object
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnselect.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
BGimage = OpenFileDialog1.FileName.ToString
TextBox1.Text = OpenFileDialog1.FileName.ToString
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnset.Click
Me.Panel1.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
My.Settings.BGimage = BGimage
Wait.Show()
End Sub
But there are more another namespaces in the form and these are,
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
So, I am facing error in the page load event code, and error is "FromFile is not a member of 'iTextSharp.text.Image' "
I am getting a blue squiggly line under "Image.FromFile" in the page load event code. and as compile error.
So, I stuck here. I can't understand what to do.
Add appropriate namespace, like this:
Me.Panel2.BackgroundImage = System.Drawing.Image.FromFile(My.Settings.BGimage.ToString)
I want my code to download a file from a website and save it to an directory that the user has selected in the FolderBrowserDialog ... i've tried this code below without success:
' Download the files
If My.Computer.Network.IsAvailable Then
Try
wClient.DownloadFile(New Uri("DOWNLOAD LINK"), FolderBrowserDialog1.SelectedPath & "FILENAME.123")
wClient.DownloadFile(New Uri("DOWNLOAD LINK"), FolderBrowserDialog1.SelectedPath & "FileName.123)
wClient.DownloadFile(New Uri("Download LINK"), FolderBrowserDialog1.SelectedPath & "FileName.123")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Here is some sample code I have written for you that should get you started.
first we declare wClient as a WebClient with Events so we can trigger what happens when the file downloads.I have used VLC Media Player as an example download, change to suit your needs. NOTE I did this with a button click event which you don't necessary need to do.
Imports System.ComponentModel
Imports System.Net
Public Class Form1
Private WithEvents wClient As New WebClient()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FolderBrowserDiaglog1 As New FolderBrowserDialog()
Dim folderPath As String = ""
Dim fileName As String = "vlc.exe"
Dim downloadFile As String = "https://get.videolan.org/vlc/2.2.6/win32/vlc-2.2.6-win32.exe" ''VLC MEDIA PLAYER
If FolderBrowserDiaglog1.ShowDialog() = DialogResult.OK Then
folderPath = FolderBrowserDiaglog1.SelectedPath
End If
If My.Computer.Network.IsAvailable Then
Dim combinePath As String = System.IO.Path.Combine(folderPath, fileName)
wClient.DownloadFileAsync(New Uri(downloadFile), combinePath)
End If
End Sub
Private Sub wClient_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles wClient.DownloadFileCompleted
MessageBox.Show("File Downloaded")
End Sub
End Class
Have a look in the wClient's event list and see the many options that are avalible such as the one that i have made that shows a messagebox once the file has been downloaded.
Webclient events https://msdn.microsoft.com/en-us/library/system.net.webclient_events(v=vs.110).aspx
How can I scrape captcha from this website
captchaImage.
I tried MSHTML but this website uses java script function to display retrieve captcha in it's src. Please try and answer me how can I achieve this.
Imports MahApps.Metro.Controls
Imports System.Net
Imports System.Windows.Forms
Class MainWindow
Inherits MetroWindow
Private Sub MetroWindow_Loaded(sender As Object, e As RoutedEventArgs)
wb.Navigate("https://www.irctc.co.in/eticketing/loginHome.jsf")
AddHandler wb.LoadCompleted, AddressOf wb_Loaded
End Sub
Private Sub btngo_Click(sender As Object, e As RoutedEventArgs) Handles btngo.Click
Dim htmldoc As MSHTML.IHTMLDocument2 = wb.Document
Dim usrtxtdoc As MSHTML.IHTMLElement = htmldoc.all.item("j_username", 0)
Dim usrpwddoc As MSHTML.IHTMLElement = htmldoc.all.item("j_password", 0)
Dim captchadoc As MSHTML.IHTMLElement = htmldoc.all.item("j_captcha", 0)
usrtxtdoc.innerText = txtusrname.Text
usrpwddoc.innerText = txtpwd.Text
captchadoc.innerText = txtcaptcha.Text
End Sub
Private Sub wb_Loaded(sender As Object, e As System.Windows.Navigation.NavigationEventArgs)
MsgBox("Loaded")
Dim htmldoc As MSHTML.IHTMLDocument2 = wb.Document
Dim htmldoc2 As MSHTML.HTMLDocument = wb.Document
Dim captchaimg As MSHTML.HTMLImg = htmldoc.all.item("cimage", 0)
Dim bitmap As New BitmapImage
bitmap.BeginInit()
bitmap.UriSource = New Uri(wb.FindResource("captchaImage"))
bitmap.EndInit()
imgcaptcha.Source = bitmap
End Sub
Private Sub wb_Navigated(sender As Object, e As NavigationEventArgs) Handles wb.Navigated
lblwbstatus.Content = "Load Completed"
End Sub
Private Sub wb_Navigating(sender As Object, e As NavigatingCancelEventArgs) Handles wb.Navigating
lblwbstatus.Content = "Navigating Please wait"
End Sub
Private Sub lblwbstatus_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles lblwbstatus.MouseDoubleClick
wb.Refresh()
End Sub
End Class
you can download source from this link
Normally you would do this:
Dim htmldoc As mshtml.IHTMLDocument2 = wb.Document.DomDocument
Dim captchaimg As mshtml.HTMLImg = htmldoc.all.item("cimage", 0)
Dim imgRange As IHTMLControlRange = htmldoc.body.createControlRange()
For Each img As IHTMLImgElement In htmldoc.images
If img.nameProp = "captchaImage" Then
imgRange.add(img)
imgRange.execCommand("Copy", False, Nothing)
Using bmp As Bitmap = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
bmp.Save("c:\test.bmp")
End Using
End If
Next
However the image has an alpha channel that doesn't get copied to clipboard because of internet explorer issues (as you can read here Copying image from page results in black image).
Other ways are to check on internet explorer cache, but that image won't be cached because of HTTP headers, so you are out of luck.
the code above work very good with consideration -to the:
1- Item type- as in your webpage target example ("IMG").
2- the image proper name example: CaptchaImg.jpg to be written as CaptchaImg.jpg
3- add reference to (mshtml) and Imports mshtml into your project
4- right-Click reference on your project --> click add reference -->
-->Browse button click -choose or navigate to --->
C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll
----> ok button click --- this will add Microsoft.mshtml.dll to your reference
finallt import to your project as (Imports mshtml).
5- change the directory bmp.Save("c:\test.bmp")---> to for example bmp.Save("c:\test\test.bmp")
for security and administration right privileged.
I am building a small app that is pulling script from within an object. I'm down to the portion where my code is pulling back the field from the object that has the script and I'm getting this error.
"reference to a non-shared member requires an object reference"
I'm not sure what to change or how to get around this. Does anyone out there have any suggestions?
Here is the code that i have so far. It's a simple app that has a combobox that you choose the company from and on button click it will get the script and show it in the textbox.
Here is my code:
Imports System.IO
Public Class Form1
Public M3System As MILLSYSTEMLib.System
Public M3Script As MILLCOMPANYLib.CScripting
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'On Error Resume Next
Try
Dim Approved As Integer
' Create a Millennium system obects
M3System = CreateObject("MillSystem.System")
M3System.Load("Millennium")
'run login script
Dim User As Object = M3System.Login()
' See if login worked
If User Is Nothing Then
'MsgBox("Login failed!")
Approved = 0
Else
'MsgBox("Login successful")
'if approved=1 then the user is able to access M3
Approved = 1
End If
'populate combo box
For Each Company In M3System.Companies
cb_COID.Items.Add(Company.Field("co").ToString)
Next
Catch ex As Exception
Me.Close()
End Try
End Sub
Public Sub btn_LoadScript_Click(sender As Object, e As EventArgs) Handles btn_LoadScript.Click
Dim CoCode As String = cb_COID.SelectedItem
Dim script As String = M3Script.vbscript
If IsNothing(cb_COID) Then
MessageBox.Show("Select a Company Code")
End If
For Each CoCode In M3Script.co
tb_Script.Text = script
Next
End Sub
I'm guessing that the line you are failing on is Dim script As String = M3Script.vbscript
If that is the case, it's because you are declaring the M3Script, but you are not creating an instance of it.
Try setting the object somewhere by adding M3Script = new MILLCOMPANYLib.CScripting to your code, or however you would load it (perhaps M3Script = CreateObject("MillSystem.Script")?)
I am using Windows Vista x64 + VSTS 2008. I am debugging the sample program from the following URL (associated sample code for this article),
http://www.codeproject.com/KB/audio-video/CaptureScreenAsVideo.aspx?display=PrintAll&fid=129831&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101&select=1160633
But I met with null pointer exception when press the write to file button, here is my screen snapshot.
http://tinypic.com/view.php?pic=14cbfop&s=5
Any ideas what is wrong?
EDIT1: here is the whole source code.
Imports WMEncoderLib
Imports WMPREVIEWLib
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(48, 80)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(216, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Write To file and Close application"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Dim Encoder As WMEncoder
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a WMEncoder object.
Encoder = New WMEncoder
' Retrieve the source group collection and add a source group.
Dim SrcGrp As IWMEncSourceGroup2
Dim SrcGrpColl As IWMEncSourceGroupCollection
SrcGrpColl = Encoder.SourceGroupCollection
SrcGrp = SrcGrpColl.Add("SG_1")
' Add a video and audio source to the source group.
Dim SrcVid As IWMEncVideoSource2
Dim SrcAud As IWMEncAudioSource
SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO)
SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
' Identify the source files to encode.
SrcVid.SetInput("ScreenCap://ScreenCapture1")
SrcAud.SetInput("Device://Default_Audio_Device")
' Choose a profile from the collection.
Dim ProColl As IWMEncProfileCollection
Dim Pro As IWMEncProfile
Dim i As Integer
Dim lLength As Long
ProColl = Encoder.ProfileCollection
lLength = ProColl.Count
'For i = 0 To lLength - 1
' Console.WriteLine(ProColl.Item(i).Name)
'Next
For i = 0 To lLength - 1
Pro = ProColl.Item(i)
If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
SrcGrp.Profile = Pro
Exit For
End If
Next
' Fill in the description object members.
Dim Descr As IWMEncDisplayInfo
Descr = Encoder.DisplayInfo
Descr.Author = "Armoghan Asif"
Descr.Copyright = "Copyright information"
Descr.Description = "Text description of encoded content"
Descr.Rating = "Rating information"
Descr.Title = "Title of encoded content"
' Add an attribute to the collection.
Dim Attr As IWMEncAttributes
Attr = Encoder.Attributes
Attr.Add("URL", "www.adnare.com")
' Specify a file object in which to save encoded content.
Dim File As IWMEncFile
File = Encoder.File
File.LocalFileName = "C:\OutputFile.avi"
' Crop 2 pixels from each edge of the video image.
SrcVid.CroppingBottomMargin = 2
SrcVid.CroppingTopMargin = 2
SrcVid.CroppingLeftMargin = 2
SrcVid.CroppingRightMargin = 2
' Start the encoding process.
Encoder.Start()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Encoder.RunState Then
Encoder.Stop()
Application.Exit()
End If
End Sub
End Class
Did you install Windows Media Encoder 9 Series and SDK as instructed by the article? My guess is that this is the culprit.
You probably don't have the encoder. Check the prerequisites (See this line: "You will be needing Windows Media Encoder 9 Series and SDK.").
Is this code still intact?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a WMEncoder object.
Encoder = New WMEncoder
The implication is that that code is missing or quietly failing.
If you put a breakpoint on the line following Encoder = New WMEncoder, what's the value of Encoder?