Sending a Postscript document to a printer using VC ++

I have a postscript file. How to send it to a printer using Visual C ++? It seems to be easy.

+1
source share
3 answers

If the printer supports PostScript directly, you can buffer the original print jobs as follows:

HANDLE ph; OpenPrinter(&ph, "Printer Name", NULL); di1.pDatatype = IsV4Driver("Printer Name") ? "XPS_PASS" : "RAW"; di1.pDocName = "Raw print document"; di1.pOutputFile = NULL; StartDocPrinter(ph, 1, (LPBYTE)&di1); StartPagePrinter(ph); WritePrinter(ph, buffer, dwRead, &dwWritten); EndPagePrinter(ph); EndDocPrinter(ph) 

Repeat WritePrinter until you have wound the whole file.

IsV4Driver () Checks for drivers of version 4, this is necessary in Windows 8 and Server 2012:

 bool IsV4Driver(wchar_t* printerName) { HANDLE handle; PRINTER_DEFAULTS defaults; defaults.DesiredAccess = PRINTER_ACCESS_USE; defaults.pDatatype = L"RAW"; defaults.pDevMode = NULL; if (::OpenPrinter(printerName, &handle, &defaults) == 0) { return false; } DWORD version = GetVersion(handle); ClosePrinter(handle); return version == 4; } DWORD GetVersion(HANDLE handle) { DWORD needed; GetPrinterDriver(handle, NULL, 2, NULL, 0, &needed); std::vector<char> buffer(needed); return ((DRIVER_INFO_2*) &buffer[0])->cVersion; } 
+5
source

This is harder than you suspect. If the PS printer is connected via a serial port or a USB port, you can simply open the device and write the file. Similarly, if the printer with the postscript is connected to the Ethernet network, you can connect to port 9100 ( telnet my.network.printer 9100 < pic.ps ) (I can’t correctly name the port number, maybe I need to smell or do some research) and write the file.

But if this is just some old printer, then you need to interpret the postscript code and send the rasterized pages to the printer.

If this is a PCL / PS combo printer, you may need to add a PCL header to enter PS mode depending on the printer settings (if everything is set to "auto detect", do not worry about this part). You will learn how to do this if you get snippets of postscript code, possibly with a different gobbeldegook instead of the desired output.

I am ashamed to say that I really do not know how to open a USB device in Windows C ++, but if that helps, the DOS path should use lpt1: as the file name (as in copy pic.ps lpt1: , which will be use the device.

If this is a shared printer, you really need to go through the network print queue, not directly to the printer.

+1
source

It is not that difficult. You can use the LPD (Line Printer Daemon) protocol to talk to the server. The protocol is simple, you can read the specification and write it yourself.

Another way is to invoke the lpr directly. However, this command is disabled in Windows 7 by default. A search for β€œlpr command windows 7” will tell you how to enable it.

0
source

Source: https://habr.com/ru/post/1215653/


All Articles