How to print files stored on local hard drive in C #?

I have a function created in C # (WinForms) that saves a file as a gif image in a local directory. How can I access it and send it to print on one of my network printers?

I have this code here right now:

internal void PrintLabels(string printerInfo, List<string> shippingLabels) { //this is where I print to printer... foreach (string labelPath in shippingLabels) { } } 

Any help?

0
c # printing winforms
Dec 16 '10 at 18:43
source share
4 answers

An alternative method would be to programmatically create a pdf document / s, which you then print using CommandLine

Take a look at the iText library.

Once you have created your files, you can print them through the command line (you can use the Command class found in the System.Diagnostics namespace)

If you are doing all this from a package, then you will also want to be notified (possibly programmatically) if something goes wrong with the print queue that you are printing to. I believe there is a class for this.

For more information on this, try here .

+1
Dec 16 '10 at 19:19
source share
— -

You can use the PrintDocument class from the .NET Framework 4.5

This MSDN article should point you in the right direction.

0
Dec 16 '10 at 18:50
source share

I have a bunch of gif images. All your links are for .txt files. This is my code:

  public void PrintShippingLabels() { //mock of what the reset of the program will produce up to this step List<string> shippingLabels = new List<string>(); for (var i = 0; i < 10; i++) { var trackingNumber = "1ZR02XXXXXXXXXXXXX" + i + ".gif"; shippingLabels.Add(trackingNumber); CreateSampleShippingLabel(trackingNumber); } Assert.AreEqual(10, shippingLabels.Count); IceTechUPSClient.Instance.PrintLabels("", shippingLabels); } public void PrintLabels(List<string> shippingLabels) { //this is where I print to printer... PrintDocument pd = new PrintDocument(); foreach (string labelPath in shippingLabels) { pd.Print(); } } 
0
Dec 16 '10 at 20:23
source share

Check the printer you have. Some devices now have the ability to print gif, jpeg, tiff, etc., without requiring conversion to PCL or PostScript data streams (or another print language). If so, you can simply send the file via the LPR protocol directly through port 9100 or directly through the Windows print queue ( http://support.microsoft.com/kb/322091 )

0
Dec 18 2018-10-18
source share



All Articles