开发者

Printing with Silverlight and com-interop

开发者 https://www.devze.com 2023-03-26 12:49 出处:网络
I\'m trying to print from silverlight without a print dialog and for that I\'m using System.Runtime.InteropServices.Automation;

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.CreateO开发者_开发百科bject("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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消