Printing with Silverlight and com-interop

谁都会走 提交于 2019-12-23 17:33:14

问题


I'm trying to print from silverlight without a print dialog and for that I'm using System.Runtime.InteropServices.Automation;

Right now I'm creating a temporary txt file that contain the text to send to printer.

using (dynamic fso = AutomationFactory.CreateObject(@"Scripting.FileSystemObject"))
{
   dynamic file = fso.CreateTextFile(cFileName, true);
   file.Write(printText);
   file.Close();
}

After that I'm using shell.Aplication to print that document.

 dynamic shell = AutomationFactory.CreateObject("Shell.Application");
 shell.ShellExecute(cFileName, "", "", "print", 1);

The question is, how can a print directly to printer without a temporary txt file?

Don't forget that I'm using Silverlight 4 out of browser and with elevated trust.


回答1:


You should be able to start notepad and send your content although this is no fun solution:

Read: Silverlight 4 - send text to Notepad and: http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.85).aspx

So basicly, 1. you start an instance of notepad. 2. Wait some time. 3. Send your text to notepad 4. Send {PRTSC} for printing 5. Ofcourse, close the instance ;)

Good luck!



来源:https://stackoverflow.com/questions/6985730/printing-with-silverlight-and-com-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!