Tician

Printer Command Language +C#

Sep 27th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. //PCL is used to "talk to a printer directly", means you don't need any drivers. To create such a file you can easily just use a text-file. A good translation you can find here: http://www.pclviewer.com/de/resources/reference/index.html
  2. Afaik PCL does not allow any comments, so if you use this sheet you have to delete my comments, they are just for showing what I did there. An example of how you start a file (oh right, the signs that are not properly displayed are called control character, you need to replace them with the escape-character, you can see those things in the RAW-format below):
  3.  
  4. E&l26A&l0o6d1E //reset printer; use A4 paper format; Portrait page orientation, 6 LPI, Top margin at 1 line
  5. &l4H //Feed from Tray 2
  6. (10U(s4148t1b5s5v13h0P //(USA Symbol set(Arial, Fontselection http://www.pclviewer.com/de/resources/font_selection.html
  7. *p150y75XHello World //Write "Hello World" at 150 pixel downwards (Y) and 75 pixel to the right (X)
  8. *p200y75XHello again //Write "Hello again"
  9.  
  10. //A normal A4 paper has 2300 pixels to the right and 3380 pixel downwards (considering there is a margin of 5 millimeter on every side)
  11. //This example draws a 50 pixel wide grey-doted border around a landscape oriented paper
  12.  
  13. *p0x0Y*c3380A*c50B*c50G*c2P*p0x0Y //Position 0; Horizontal dots; vertical dots; Grey Scale; print grey scale; position 0
  14. *p0x2300Y*c3380A*c50B*c50G*c2P*p0x0Y
  15. *p0x0Y*c50A*c2300B*c50G*c2P*p0x0Y
  16. *p3330x0Y*c50A*c2300B*c50G*c2P*p0x0Y
  17.  
  18. //Now the question: How do you print this? Simple sending the text-file to a printer does not work, you would simply get the text you write inside it. If you go to the "uninstall software" screen (I only know it from Windows 7) there is an option to the left which says "activating or deactivating windows functions". This opens a small windows (loads for a while) where you have to open the first tab of "Print and document settings" and tick the LPR setting.
  19. //With this in your pocket you can simply open a command console and type in the following:
  20.  
  21. lpr -P printername pathToFile
  22.  
  23. //The whole command with all usable arguments is found here: https://technet.microsoft.com/en-us/library/cc731926(v=ws.11).aspx
  24. //An actual exmaple for me to be able to print is this:
  25.  
  26. lpr -S printserver -P prt-de-xxx-009 C:\Temp\abcde.txt
  27.  
  28. //To be able to use that print-command in C# use this for 64-bit machines (only Win 7?):
  29.  
  30. ProcessStartInfo infoPRT = new ProcessStartInfo();
  31. infoPRT.WindowStyle = ProcessWindowStyle.Hidden;
  32. infoPRT.FileName = "C:\\Windows\\Sysnative\\lpr.exe";
  33. infoPRT.Arguments = " -S printserver -P prt-de-nsu-009 C:\\Temp\\test.dru";
  34.  
  35. Process q = new Process();
  36. q.StartInfo = infoPRT;
  37. q.Start();
  38.  
  39. //Normally the path to lpr.exe is in the system32-folder. You might notice you "don't have the Sysnative folder", but believe me you do. The explorer.exe you are working with is a 64-bit application and no matter what you do you will not see the Sysnative folder, because it can only be accessed by a 32-bit application (which the project in Visual Studio is per default)
  40.  
  41. //Hope this helps, wish you best luck!
Add Comment
Please, Sign In to add comment