I want to write a application in C++ or C# that will behave as a printer driver when installed. It will be available in the drop down list in Print dialog but instead of printing it will call into my code.
I think there may be some interfaces that Windows provide to write printer drivers.
Windows provides loads of interfaces. Do you know what sort of a printer driver you want to write? At present, Windows supports three flavors of printer drivers -- PostScript, Unidrv and XPSDrv (the latter on XP/2003 Server with EP 1.0 and upwards only). Most of the time, it suffices to write a driver plug-in instead. Read up on INF architecture to know these things get installed, specially the section on minidrivers.
As suggested, you will need the WDK to be able to build a driver or a plug-in thereof. Note that drivers do not use the Visual Studio IDE or compilers. The WDK comes with a compiler of its own. You can always hook up the latter with VS, but that's a different story.
The WDK has setups to target different OS-es. You will have to know which OS (or set of OS-es) you want to address and choose the appropriate setup.
I want to write a simple driver that will displays in the list of printers.
I don't see how that will be helpful. If you are writing a driver, why would you want a list of all other drivers present on the system?
Printing to this driver will call into my code so that I can do stuff like create a PDF of the document, calling the Web Service etc.
Interesting! You can achieve all those things in a UI plug-in. An UI plug-in is a dll that is loaded when you select the Advanced driver properties.
To get started with UI plug-ins take a look at the sample oemui source code in the WDK.
What you are asking is not available in Windows.
You could have your own printer driver developed using PostScript, UniDrv, XPSDrv driver. When the driver is installed as part of the Add Printer which will create a print queue with the driver. Discovery and device installation is another topic.
This driver will be called by the Windows Print system when print job is submitted from your app.
Windows Print system consist of Print Spooler, Print Processor, Port Monitor, Language Monitor.
When your app call Win32 or .NET print APIs which will call common print dialog or Modern Print Dialog component to display the print dialog interface which list the printers. When you submit the print job, spooler generates the spool data in XPS format and sent it to your driver. Your driver process the driver and write out to the spooler or save it to file depends on the port configuration.
I'm not sure about it to be displayed in the list but I've never tried this C++ code:
#include <fstream>
Namespace Drivers{
Class Printer{
Const IOStream Printer("PRN");
Void Send(char a[]){
Printer<<a;}
Char GetStatus[](){
Char a[];
Printer>>a;
return a;
};
}
Related
has anyone had any dealings with the above mentioned printer or one like it? I have been handed the task of introducing this printer into our c# project and am not sure where to start. I have created a sample .lbl file using Averys recommended software to get all of the dimensions correct. (Nicelabel SE)
the printer is connected to the PC via Network.
here is a Sample Image of the project that I am trying to create, I have spoken to one of the engineers at Monarch and he is helping me with creating a base file to send to the printer, and having some of the data as a variable.
ideally it would be good if I could launch a dos program which would handle this for me, but I seem to really be pulling at straws here.. I have seen the Zebra SDK, but im not sure if this printer is compatible.
Thanks.
I have spoken to the Guys from Avery and they built a template for me to use, and with a variable section in the code I was able to put in my own settings to get the required output.
To send the file to the printer I was able to use the LPR Service in windows using a batch file.
I'm working on a C# desktop application where I need to change some printer settings and print some pictures. In my program I already can set the Paper Size, Printer Name, etc... If I go into the Advanced Options of the printer preferences, there is a section called "Printer Features". I cannot figure out how to access the parameters in the printer settings. For example there is "Border", "Overcoat Finish", "2inch cut", etc.. Specifically what I'm interested in is "2inch cut".
How can I get at these properties in run time?
UPDATE
I changed the picture and question a little bit to be more specific.
Okay, so I came across a solution that works very well for me, hopefully this will help others.
After a bit of research, I found out that my printer just isn't set up to allow those features to be accessed through the driver. So what I did was create a second profile in the printers and devices in windows that connects to the same printer on the same port with the same drivers. Then with my program I just select the different printer profile based on what my needs are. Works like a charm.
Thanks to everyone who contributed.
You can set the printer quality using dmPrintQuality member of the DEVMODE structure. Other printer features may not be applicable for all printers. Some printer drivers may expose properties which are quite different to other print drivers. This is normally done using the dmDriverExtra extra member of the above structure. As MSDN says dmDriverExtra is private printer data:
Contains the number of bytes of private driver-data that follow this
structure. If a device driver does not use device-specific
information, set this member to zero.
Gone through the already existing posts on this topic, but my requirement is some what bit different.
Print jobs over the Network installed printers, upon a action in client side browser. Web server has got all printers in it, based on the client data, we need to print with client given configuration straight away, sending the job to printer(may be a different locations - but this is not a problem since the printers are in same network). I have seen printing architecture, Win32_print Class, SNMP, System.drawing.Printing, System.Printing.... but couldn't find the way to achieve this.. (Asp.net,C#)
-Files are been already existed in a server folder, just I need to pick up and send to a printer with client Selected Configuration...
update:I have to use JDF approach because all the files are PDF files. I am able to create JDF files with the selected configuration but sending this JDF to printer(JDF enabled) making me tough... There is JMF which post the JDF to printer, but not sure how to implement it.. still finding the ways, will be great if some one helps in this.
Something I can answer! 8-) I'm actually working on a project that uses this, right now.
Do not use Acrobat Reader as any sort of server application. It has a User Interface that will pop up on a screen that doesn't exist, at an unexpected time and freeze your app, waiting for a click that will never happen.
Use Ghostscript. Ghostscript is free, Open Source and will work perfectly for what you want. Out-of-the-box it consists of a DLL and a command line inhterface, however there is an API and a ton of different interfaces including .Net, and versions for both Windows and Linux.
On a more "overview" type of note, the reason you can drag a PDF into a printer on your workstation is because Acrobat Reader contains the code and hooks to allow this. Windows doesn't actually contain native functionality to print PDFs.
It may well be that I have to write something overly complex for this and that there is no regular way to do it, but:
How can I get myself a list of all available printer drivers much like the add printer wizard does when it displays them by manufacturer then by printer? I basically need a custom add printer dialog and without this, I'm a bit stuffed ;)
Like this: (ignore the arrow, borrowed image)
I would also need the path to the .inf file denoted by the drivers in the list
EDIT: A little background:
I am attempting to add a printer by invoking the add printer wizard (with elevated privs) in a TS session, adding the printer to the correct TS Port and then attempting to save the information for that printer so as upon login the users printer is added automatically based on values I've saved.
So far, I've not been able to find a way to get the driver information (preferably the actual path to the .inf file for that printer driver as then I can use PrintUI to install the printer) after adding the printer.
As such, I am resorting to a custom dialog to match the printer driver. As the tool is only used upon initial printer install and only by administrators I don't mind having a secondary dialog where you choose the driver a second time just so I can save the information.
EDIT: Targeting Windows Server 2008 R2 (Win32_PrinterDriver doesnt appear to work)
You can query WMI for information on the printer drivers that are currently in use. The Win32_PrinterDriver class details the available properties. You can use classes in the System.Management Namespace to perform the queries.
SelectQuery selectQuery = new SelectQuery("Win32_PrinterDriver");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
foreach (ManagementObject printerDriver in searcher.Get())
{
// Your code here.
}
You can access the properties by indexing to them, i.e. printerDriver["DriverPath"].
Also see WMI Queries topic on MSDN.
On an interesting side note, Microsoft has since added a Get-PrinterDriver commandlet to some versions of PowerShell (on Windows 10, etc.) that does something pretty similar to the above code.
UPDATE: I was looking through old questions and discovered the DriverStoreExplorer project on GitHub. There's a lot to the code that enumerates all printer drivers, so it does not make sense to reproduce it here.
I need to create a C# application that will run in server in that i need to get the printer details like printer status, number of pages printed.The system which is requested for the print that systems username and system name.
If the system connected in the network requested for printing then i need to get the system details in my application
how can i do this?.
sorry for my bad English.
The classes in the .NET 3.0 System.Printing namespace are your starting point. Beware that the amount of functionality available is pretty limited. You can't get an event out of them that tells you that a new print job got started. Something as simple and obvious as counting printed pages is not possible.
This is a core architectural limitation, Windows leaves a lot of the printing management up to a the printer driver. And every printer manufacturer makes their own. Which explains that counting pages isn't supported for example, the driver sends some kind of proprietary control command to the printer to tell it to generate copies of a document rather than Windows spooling the same document repeatedly. That's efficient but not easily observed. These manufacturers also usually have their own printing management software, you probably ought to look at that first.