Virtual printer : intercept data sent to printer using c# - c#

i'm creating a PDF Creator equivalent and I have to add some options to it while using C# language.
I would like to know how I can intercept data that was sent to the printer and how I can save it in a c# variable.
My printer launches the program as follows. Redmon is used as a redirection port

Program's like Redmon allow you to save the data to file. Save it as a temp file then pass in the filename as a command line argument. You could also pass it in as stdin/stdout which is how Redmon passes it into Ghostscript but temp file solution should work well and is easy to implement.

Related

Windows driver only save binary file

I need own printer on Windows. I just need when I from any application (adobe reader, IE etc.) have open html page, or PDF when I click on file, print choose printer and this printer only take original input data as binary and just save to file disk.
I try to solve this problem with universla PS drivers for windows, but convert file from ps back to PDF or XPS can destroy PDF. Do you know some drivers or example?
Windows printer drivers according to documentation on MSDN can be only in C++. So I like avoid to write driver by own. I have my own port which can take document from printer and save them. But I still need driver which just take input after Ctrl+P arise and send to my port or save to disk.

Printing postscript file from C#

I have an application that creates a temporary postscript file.
After it runs its main routines, it tries to print the file. However, when I send RAW data to the printer, nothing comes out.
I've also tried the PrintDocument class using this example from the MSDN and that prints the postscript code instead of the resulting graphics.
Is there a way to print a postscript file from C# or would I have to use an outside program such as GhostScript?

Create a pipe file in windows/.net

I am using an older program that generates it's output into a file. I can specify on the command line the file to use, but it must go to a file (no option to send to stdout).
I would like to stream that output as it is generated (not wait until the file is finished). In *nix, I would create a named pipe, and use that "file" as the output.
Can this (or something similar) be done in Windows? Can it be done in pure C#, or only c/c++/pInvoke? Is there some library that can do this cross platform?
From your .Net application, you can spawn the legacy application as a Process, for which you can define, among other things, its standard output stream. You can use a file stream or any other kind of stream to redirect the process's output.

Print a PDF server side from ASP.NET

I need to take a PDF file url, send it as a parameter to a web service that will print it on a network printer. It has to be done server side without any user interaction.
Do you know some libraries that we can use to acheive that ? We look at different options like iTextSharp but it looks like there's no way to print from that library.
Thanks.
If you can download the file and save it as a PDF and have Acrobat Reader installed you can use a command line to print it (shell it).
http://www.robvanderwoude.com/commandlineswitches.php#Acrobat
Print a PDF file silently:
AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]
It would be nice to know what commercial component you used...
I had to something like that, but using PCL. We used winspool.drv to open the printer, start a document then a page, write out the bytes, then end the page & document and close the printer. We installed PCL drivers for the printer on the local machine to print to a network printer.
You might be able to do something like that with Postscript drivers. A quick test would be to to a binary copy of a PDF to the printer using the command prompt and the /B switch on copy. I think you specify the PDF and the printers network share as source/destination. Use a small PDF to avoid getting a ream of random characters in case it doesn't work.
We'll finally use a commercial component that does all this by itself.
Thanks for your help.

Create virtual 'shredder' printer

I need to create a virtual printer that 'shreds'
Basically here is my problem. I have a software program that needs to 'print' a file before it will save it. I want to be able to print to my shredder so that it saves the document, but I don't actually want the document printed. So I need to print to a program that securely deletes the document and shows as a driver in Windows.
How would I go about doing this in C# of VB.Net?
No need to write code for this just print to nul. This has worked since DOS. Just create a new printer, printing to a local port, and put nul in there for the port name.
http://www.markmmanning.com/blog/2009/01/creating-fake-printer-devnull-for.html

Categories