简体   繁体   中英

Printing with Silverlight and com-interop

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM