I am working on an ASP.NET application and need to send documents to a network printer. I have utilized the PrintServer and PrintQueue to achieve the purpose as follows:
using System.Printing;
private void PrintTicket
{
var server = "Network Server Name";
var filePath = "File to Print";
var printer = "Network Printer Name";
var printerServer = new PrintServer(String.Format(#"\\{0}", server));
var printQueue = printerServer.GetPrintQueue(printer);
printQueue.AddJob("New Printing Job", filePath, false);
}
The network printer can be found and the print job is executed.
However, the performance is very slow. It took 5-10 seconds to start printing when method printQueue.AddJob() is executed.If the printer is connected to my local machine, there is no performance issue at all.
Any suggestions? Thanks in advance.
Instead of using PrintQueue class you can simply use File.Copy(filePath, printerDestination, true);
I have tried both the options i.e. using printqueue as well as file copy and file copy is much faster compare to using printqueue class.
Thanks,
Arnab
Related
I'm looking for a way to create a hyperlink to a particular folder in Worksite.
So far, I've only come up with a macro linking files on the basis of their database numbers but folders do not have database numbers (I think).
Another thing is that I wanted the folders to be opened in Outlook (Worksite is connected with Outlook and we access folders through it)
What I try to accomplish is creating hyperlinks in Excel for easy folder access (just like hyperlinks to files).
Does anybody have a clue if it's even possible? If yes, I'd appreciate an example of a code for this.
Thanks in advance.
Yes it's possible.
You don't mention which version of the iManage client you're working with however I'm going to assume FileSite 9.x. Installed with that client is a custom protocol handler which supports a custom URI scheme.
In effect this allows you to compose a hyperlink with plain text which you can then embed in your web page, or just start a new process in Windows to let the default browser load it up.
The custom protocol handler will parse it and then start up whatever iManage client it can (FileSite in your case) and then navigate to the correct folder.
Format is iwl:dms=[ServerName]&&lib=[DatabaseName]&&page=[FolderID]
Here's some C# that builds out such a string
var serverName = "MYSERVERNAME";
var databaseName = "MYDBNAME";
var serverName = "1234"; // internal numeric ID of folder (MHGROUP.PROJECTS.PRJ_ID in database, or IManFolder.FolderID via iManage COM API object model
var sb = new StringBuilder("iwl:");
sb.Append($"dms={serverName}");
sb.Append("&&");
sb.Append($"lib={databaseName}");
sb.Append("&&");
sb.Append($"page={serverName}");
// sb.ToString() will now output the hyperlink reference to your folder which you can pass to your web browser..
Sub Folder_link
Dim dmsIM As IManDMS
Dim dmsS As IManSession
Dim dmsD As IManDatabase
Dim FdR As IManFolder
Dim FdrLoc As String
Dim FdrID As Long
Const ServerName As String = <DMS name>
Const DatabaseName As String = <DatabaseName>
FdrLoc = "\\{DMS name}\{DatabaseName}\Main Folder\SubFolder\SubSubFolder\TargetFolderName"
Set dmsIM = New ManDMS
Set dmsS = dmsIM.Sessions.Add(ServerName)
dmsS.TrustedLogin
Set dmsD = dmsS.Databases.ItemByName(DatabaseName)
Set Fdr = Imanage.ImanFolder.Location (FdrLoc)
FdrID = Fdr.FolderID
With ThisWorkBook.WorkSheets(1).Range("A1")
.Hyperlinks.Add _
Anchor:=Selection, _
Address:="iwl:dms={serverName}&&lib={databaseName}&&page=" & FdrID, _
TextToDisplay:="link"
End With
End Sub
in a mobile application i need to send an image which the user either took with the camera or picked from a cameraroll.
I am using the starling framework and feathersUI ( although i think this does not matter to problem )
When the mediapromise is loaded using loadFilePromise i use the following code to deal with the image data:
_mediaLoader = new Loader()
//loading the filePromise from CameraRoll
_mediaLoader.loadFilePromise(_mediaPromise);
_mediaLoader.contentLoaderInfo.addEventListener(starling.events.Event.COMPLETE, onLoadImageComplete);
private function onLoadImageComplete(event:flash.events.Event=null):void {
//creating the starling texture to display the image inside the application
var texture:Texture = Texture.fromBitmapData(Bitmap(_mediaLoader.content).bitmapData, false, false, 1);
//now trying to load the content into a bytearray to send to the server later
var bytes:ByteArray=_mediaLoader.contentLoaderInfo.bytes;
}
the last line of code results in a Security error:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2121: Security sandbox violation: app:/myapp.swf: http://adobe.com/apollo/[[DYNAMIC]]/1 cannot access . This may be worked around by calling Security.allowDomain.
I tried
Security.allowDomain("*")
as a test
but then i get:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
As a workaround i write my own png ByteArray inside the Application from the loaders BitmapData using Adobes PNGEncoder Class:
var ba:ByteArray=PNGEncoder.encode(Bitmap(_mediaLoader.content).bitmapData)
But this takes a significant amount of time ...
I also tried the FileReference to load the image but
_mediaPromise.file
and
_mediaPromise.relativePath
are both null.
What am I doing wrong? Or is this a known problem ?
Thanks!
Hello I have found a solution based on a post about the processing of exif data mentioned here: http://blogs.adobe.com/cantrell/archives/2011/10/parsing-exif-data-from-images-on-mobile-devices.html
the crucial code
private function handleMedia(event:MediaEvent):void{
_mediaPromise=event.data as MediaPromise;
_imageBytes=new ByteArray()
var mediaDispatcher:IEventDispatcher = _mediaPromise.open() as IEventDispatcher;
mediaDispatcher.addEventListener(ProgressEvent.PROGRESS, onMediaPromiseProgress);
mediaDispatcher.addEventListener(flash.events.Event.COMPLETE, onMediaPromiseComplete);
};
private function onMediaPromiseProgress(e:ProgressEvent):void{
var input:IDataInput = e.target as IDataInput;
input.readBytes(_imageBytes, _imageBytes.length, input.bytesAvailable);
};
private function onMediaPromiseComplete(e:flash.events.Event):void{
_mediaLoader = new Loader();
_mediaLoader.loadBytes(_imageBytes)
};
works like a charm for me on ipad and iphone.
I am trying to send data from a VB6 program to a ticket printer Via TCP/IP. The only VB6 way I have found to try and do this is using the WinSock Control.
I use the following code to connect
WinSock.Protocol = sckTCPProtocol
WinSock.RemoteHost = txtIPAddress.Text
WinSock.RemotePort = txtPort.Text
WinSock.Connect
And then try and send the data as follows
WinSock.SendData ("<F8>" & txtPrint.Text & "<p>")
Everytime I try and do this, it fails because the Winsock.State is 6 (Connecting). This just stays at connecting and never connects or fails. I am able to connect to the printer using this IP/Port combo outside of VB6. Is there anything I may be doing wrong? Can the WinSock control do this?
In a .net program provided, this seems to be accomplished by doing the following:
CONNECT
client = new TcpClient(ip_address, 9100);
s = client.GetStream(); //s is System.Net.Sockets.NetworkStream
s.ReadTimeout = 500; //attempt to read for up to 0.5 seconds
sr = new StreamReader(s); //create read stream
sw = new StreamWriter(s); //create write stream
sb = new BinaryWriter(s); //create binary stream
sw.AutoFlush = true; //set write stream to flush data when < full buffer
SEND:
sw.WriteLine(command);
Thank you.
You are missing up concepts. I remember this from 15 years ago.
Winsock is for work with a protocol. You must know the printer protocol. Is not just sample text.
I have an external application and I want it to display some information on top of the browser window. My bootstrapped extension needs to pass the browser window handle (native HWND) to my application, along with some other useful information about the window. I'm able to do the communication between them, the only thing that is missing is a way to get the native HWND of the Firefox window.
I read a lot about it and although I belive it's possible, I couldn't find a working solution. Here's what I've tried so far:
This one should give me nsIBaseWindow, so I could get nsIBaseWindow.nativeHandle or nsIBaseWindow.ParentNativeWindow, but no success:
var window = SomeDOMWindow; // Informative
var baseWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIXULWindow)
.docShell
.QueryInterface(Components.interfaces.nsIBaseWindow);
The above code is widely spread on forums, but I couldn't get it to work for me.
The other one does not seem to be much accurate since it gets the HWND based on the window's class and title, which can lead to wrong results:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("user32.dll");
var fww = lib.declare("FindWindowW", ctypes.winapi_abi,
ctypes.voidptr_t, ctypes.jschar.ptr, ctypes.jschar.ptr);
var sfw = lib.declare("SetForegroundWindow", ctypes.winapi_abi,
ctypes.int32_t, ctypes.voidptr_t);
var hwnd = fww("MozillaWindowClass", document.title);
setTimeout(function() {
sfw(hwnd);
lib.close();
}, 3000);
Any help would be appreciated.
window must be a root one (i.e. an instance of ChromeWindow)
The following code should work
var win = Cc["#mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("navigator:browser");
var basewindow = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.nsIBaseWindow;
var nativehandle = basewindow.nativeHandle;
The problem was that I was querying the wrong interface from the subject param in the xul-window-registered observer. I need to get an nsIDOMWindow instead of an nsIXULWindow so the first code mentioned in my question works. So now I'm doing the following, with some piece of code #Noit suggested:
observe: function(subject, topic, data) {
var newWindow = subject.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
var basewindow = newWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.nsIBaseWindow;
var nativehandle = basewindow.nativeHandle;
}
And it works!
Thank you very much for your help.
I also just came across this, it might be nice:
Cu.import("resource://gre/modules/ctypes.jsm");
/*start getcursorpos*/
var lib = ctypes.open("user32.dll");
/*foreground window stuff*/
var FindWindowA = lib.declare('FindWindowA', ctypes.winapi_abi, ctypes.uint32_t, ctypes.jschar.ptr, ctypes.jschar.ptr)
var GetForegroundWindow = lib.declare('GetForegroundWindow', ctypes.winapi_abi, ctypes.uint32_t)
function doFindWindow() {
var wm = Cc['#mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var title = wm.getMostRecentWindow('navigator:browser').gBrowser.contentDocument.title;
Cu.reportError('title=' + title)
var ret = FindWindowA('', title + ' - Mozilla Firefox');
//var ret = GetForegroundWindow();
Cu.reportError(ret);
}
/*end foreground window stuff*/
The code in the answer of user 'paa' worked until Firefox version 69.
If you execute it in Firefox 70 you will get an exception:
TypeError: win.QueryInterface is not a function
This is strange because the variable win has the same content in Firefox 69 and 70.
When I execute alert(win) I get: "[object ChromeWindow]" in both browsers.
And alert(win.document.title) displays correctly the title of the document in both browsers.
I downloaded the sourcecode of both Firefox versions to compare them and possibly find the cause. But the source code of Firefox is huge (2 Gigabyte) and nearly completely free of comments. I found that I'm wasting my time with that approach.
It is extremely difficult to understand sourcecode of Firefox which runs spread over multiple processes which communicate with each other. It seems that the content of the variable win corresponds to the C++ class mozIDOMWindowProxy or nsChromeOuterWindowProxy. But these seem to be only wrapper classes for other classes. Finally I gave up trying to understand Firefox sourcecode.
But playing around for some hours I finally found a solution by try and error.
It is even simpler:
var baseWindow = win.docShell
.treeOwner
.nsIBaseWindow;
It works on Firefox 70 up to 79 (which is currently the latest version). However this new code does not run on Firefox versions <= 62. On Firefox 62 or older you get the error
TypeError: win.docShell is undefined
So the Firefoxes from 63 to 69 allow both versions of code. Maybe in version 70 the QueryInterface() has been removed because it is not needed anymore and has become legacy?
NOTE: In Firefox 68 they made another change. Now there are 2 native windows: The toplevel 'MozillaWindowClass' now has a child window 'MozillaCompositorWindowClass' which runs in another process and draws the web content.
I'm currently having an issue with FMS4 developer edition on both Linux (x64) and Windows XP (x86).
When I stream a webcam using ns.publish("foobar", "live") I can watch the live stream on another client, however when i use ns.publish("foobar", "record"); neither broadcasting nor recording works.
Using the "live" parameter the client appears in the log files and in the administration console as "publishing", using "record" the client appears as "idle".
Is there anything I need to configure besides LIVE_DIR in fms.ini?
Is this a restriction in the developer edition?
Is there something else I'm missing?
Here is the relevant part of the code (condensed):
var camLive:Camera = Camera.getCamera();
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
var ns:NetStream;
nc.connect("rtmp://192.168.1.63/live/");
function netStatusHandler(event:NetStatusEvent):void {
if (event.info.code == "NetConnection.Connect.Success") {
ns = new NetStream(nc);
ns.attachCamera(camLive);
ns.publish("foobar", "record");
}
}
Thanks in advance!
Fabian
The problem is the live application. You can create an empty folder inside "applications", call it "test", then stream to "rtmp://192.168.1.63/test" with parameter "record". According to forums.adobe.com/thread/827134?tstart=0