I'm using jSignature javascript to save a signature to SVG. Now I'm trying to put that SVG on top of a PDF document over a signature blank.
I'm able to do it by converting the SVG to a file, opening that file with SVG (SVG Rendering Library 2.3.0) and turning it into a stream which I then put onto the PDF with PDFSharp. My issue is that I can't get the SVG Library to load from a string. It has to load from a file. I'm pulling these signatures from a Database along with their form related data.
Dim FileText As String
Dim Bytes() As Byte
Using DB As New wotcDB
FileText = (From t In DB.interviews Where t.ID = 1 Select t.Signature).FirstOrDefault
End Using
Bytes = System.Text.Encoding.ASCII.GetBytes(FileText)
Using DataStream As New System.IO.MemoryStream(Bytes)
svgDocument = Svg.SvgDocument.Open(DataStream) 'Issue
End Using
The error I get is as follows;
Severity Code Description Project File Line Suppression State
Error BC30518 Overload resolution failed because no accessible 'Open' can be called with these arguments:
'Public Shared Overloads Function Open(Of T As {SvgDocument, New})(path As String) As T': Type parameter 'T' cannot be inferred.
'Public Shared Overloads Function Open(Of T As {SvgDocument, New})(stream As Stream) As T': Type parameter 'T' cannot be inferred. WOTC-FE d:\Programming\Applications\frmDebug.vb 54 Active
I hate the idea of creating a file to convert to a graphic when the overloads clearly show that I can use streams. What am I doing incorrectly?
Open the svg file in Notepad and check that it is actually using ASCII encoding. I think it is more likely that it is UTF-8. If so, use
Bytes = System.Text.Encoding.UTF8.GetBytes(FileText)
instead.
I found the answer. It was something I already tried and though failed, but now it works. Since the type wasn't infer able, I had to declare it. I tried doing this as stream and it failed. Well today I decided to work through it and, I got it.
mySVG = SvgDocument.Open(Of SvgDocument)(newStream)
It's so obvious and I tripped over it. So to anyone else having this issue, that solves it. Please note that my program is running Option Explicit, Option Strict.
Related
I'm editing a legacy program in VB when most of my computer programming experience is in C#. The program in question compiles fine but when running I get to a certain function call to a DLL file and I get the following:
System.InvalidCastException: 'Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'.'
The arguments that are causing the issue are Dim'd As Integer. The function wants the arguments ByRef As Array. However, even when redefining the arguments As Array it says:
'Unable to cast object of type 'System.Int32[*]' to type 'System.Array'.'
EDIT
To try and give "minimal, complete, and verifiable example" as suggested by ItsPete here is some code.
I am using DA 1 OPC Wrapper DLL. This project is something I had to add a few part numbers to, not something I wrote from scratch.
Dim ConnectedOPCServer As New OPCAutomation.OPCServer
Public OPCItemCollection As OPCAutomation.OPCItems
Public gConnectedGroup As OPCAutomation.OPCGroup
Dim ConnectedServerGroups As OPCAutomation.OPCGroups
Dim ItemServerHandles() As Integer
Dim ItemServerErrors() As Integer
Dim OPCItemIDs() As String
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Kepware.KEPServerEX.V5")
ConnectedServerGroups = ConnectedOPCServer.OPCGroups
gConnectedGroup = ConnectedServerGroups.Add("Group1")
gConnectedGroup.UpdateRate = 200
gConnectedGroup.IsSubscribed = True
Call Add_OPC_Items() 'This adds tags to the OPC collection by assigning elements of the OPCItemIDs array to tag names
OPCItemCollection = gConnectedGroup.OPCItems
OPCItemCollection.DefaultIsActive = True
OPCItemCollection.AddItems(ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors)
I think that is all that is needed. Like I said...I just expected to add a few part numbers to a drop down selection and not have to dig neck deep into debugging this so I'm kinda out of my depth.
Hans Passant that might be promising. But that looks like it is for C# or C++ and not VB. I dont know how there are many duplicates...searching for Int32[*] didn't return much between Google and Stackoverflow's own search.
And holy crap Jimi that is like a day of reading.
I have to generate a Smart Form in PDF format. I have to save this output (in any possible format which I would say is type either string or xstring) in a Z table so it can be generated again without the processing.
Could you please clarify if there is any way of saving the Smart Form PDF in xstring type?
I have looked into the output of function module that generates the Smart Form and tried to look for xstring but was unable to find it.
In the CONTROL_PARAMETERS importing parameter of the function module you use to output the Smart Form, pass the field GETOTF = 'X' in order to receive the field OTF_DATA from the exporting parameter JOB_OUTPUT_INFO.
Then you can convert the field OTF_DATA into PDF format with the function module CONVERT_OTF.
That gives you a binary table that you can convert to the xstring type using the function module SCMS_BINARY_TO_XSTRING.
So I made this and someone has submitted a new VB.NET hello world example:
Module m1
Sub Main()
Console.out.writeline("Hello World")
End Sub
End Module
Is this valid VB.NET? I don't know the language, so wanted to check it.
The example that is currently on the website is:
Console.WriteLine ("Hello, World!")
What I'm mainly questioning is the Console.out.writeline - is this right?
Thanks in advance. :)
Yes, this is correct. Console.WriteLine and Console.Out.WriteLine are equivalent.
The documentation for Console.WriteLine says: "Writes the specified string value, followed by the current line terminator, to the standard output stream."
The documentation for Console.Out says: "Gets the standard output stream."
Console.Out is a TextWriter which is used for outputting text to a stream. The documentation for TextWriter.WriteLine says: "Writes a string followed by a line terminator to the text string or stream."
Console.WriteLine is basically just a shortcut for Console.Out.WriteLine.
They are equivalent. Though the the Console.Out property can be set to a stream other than the standard output.
From MSDN:
This property is set to the standard output stream by default. This
property can be set to another stream with the SetOut method.
Note that calls to Console.Out.WriteLine methods are equivalent to
calls to the corresponding WriteLine methods.
Here is my extension method:
Public Module HtmlExtensions
System.Runtime.CompilerServices.Extension
Public Function ReverseMapPath(ByVal html As HtmlHelper, ByVal path As String) As String
Dim appPath = HttpContext.Current.Server.MapPath("~")
Dim res As String = String.Format("{0}", path.Replace(appPath, "/").Replace("\", "/"))
Return res
End Function
End Module
My web.config has an entry for my namespace
Everything was working just fine. I started adding more code to the project and now I get an error that looks like I am loading the extension method twice but I cannot figure out why. The error is:
path.page.vbhtml(9): error BC30521: Overload resolution failed because no accessible 'FunctionName' is most specific for these arguments:
Extension method 'Public Function FunctionName(path As String) As String' defined in 'namespace.Extensions.HtmlExtensions': Not most specific.
Extension method 'Public Function FunctionName((path As String) As String' defined in 'namespace.Extensions.HtmlExtensions': Not most specific.
I don't understand why this has just crept up. Clearly I changed something but undoing everything doesn't help. The error seems more behind the .net framework. Any ideas?
I just ran into this issue. If you read the link CrazyTim commented, the problem comes from VS adding a reference in the project to itself.
If you're running into this issue, VS might have added a reference in your project to itself. Delete the reference, and you'll be right as rain.
It appears that it was a namespace issue. My extension class had Global.ProjectName as the namespace. Once I changed that everything worked. It must have been loading it twice due to the namespace.
I'm working on a vb.net application that interacts with a (third party provided) web app to provide additional functionality (e.g. removing menu items, pulling information from the pages, etc.). The web app is completely driven by javascript but is hosted in asp.net and is only used with Internet Explorer.
I'm trying to read properties from a javascript object and execute some of it's functions. I've managed to get hold of the javascript object by getting the mshtml.HTMLDocument of the iframe the script resides in and using the following code:
Dim jsObject as Object
jsObject = htmldoc.Script.jsObject
jsObject exists as a {System.__ComObject} and i can use it to execute any of it's functions or read it's properties as follows:
Dim value as String = jsObject.FunctionThatReturnsAString()
jsObject.FunctionTHatDoesSomethingInWebApp("Param1", "Param2")
This works great. However, when I leave the page/frame with jsObject in and return to it, the same code throws an exception when getting the javascript object from the frame again (i.e. executing the following line):
jsObject = htmldoc.Script.jsObject
Exception: Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
If I stop debugging and restart, it works again (until i leave the page, etc.). I'm not sure what's happening that's causing the javascript object to disappear as far as my app's concerned. I'm presuming it's due to my app holding a reference to the COM object and i need to release it in some way (particulary as it's got a base type of MarshalByRefObject - which makes sense as it's being passed between app domains).
Why is this happening? Is there a better way of accessing a javascript object, it's properties and functions?
I've found what is, in my case, a better way of achieving what I need. Instead of accessing the jsObject directly as a COM Object (and worrying about Marshaling, etc.), I either use:
execScript to call functions with no return value or
create a hidden div element in the frame i'm working in, set the innerHTML of that div equal to whatever javascript variable/function return value that i'm interested in using execScript and then read that value seperately from the DOM
To read a variable/function return i use the following vb.net function:
Private Function getJScriptVariable(ByVal JScript As String)
Dim command As New StringBuilder()
command.Append("var e = document.getElementById('Matt_JScriptReturn');")
command.Append("if (e == null) {")
command.Append("var e = document.createElement('div');")
command.Append("e.id = 'Matt_JScriptReturn';")
command.Append("e.type = 'hidden';")
command.Append("document.body.appendChild(e);")
command.Append("}")
command.Append("e.innerHTML = ")
command.Append(JScript)
command.Append(";")
'fMaster is the frame containing the javascript's mshtml.IHTMLWindow2
fMaster.execScript(command.ToString(), "JScript")
'N.B. fMaster_Document is the fMaster's mshtml.HTMLDocument
Return fMaster_Document.getElementById("Matt_JScriptReturn").innerHTML
'Optionally execScript to remove element from DOM at this point
End Function
Then i would use that function as follows (respecting my example in the original question):
Dim value as String = getJScriptVariable("jsObject.FunctionThatReturnsAString()")
To execute javascript code without needing to return a value I simply execute it as follows:
fMaster.execScript("jsObject.FunctionTHatDoesSomethingInWebApp('Param1', 'Param2')")
I'd still be interesting in finding out why i had the problem earlier with the javascipt object being unable to access after leaving the page and returning, however this solves my problem so i'm happy for now! I hope this helps someone else at some point.