Reputation: 6188
I have a function created in C# (WinForms) which saves the file as gif image in local directory. How can I access it and send it to printing to 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?
Upvotes: 0
Views: 4775
Reputation: 11876
Since "way back when" the default GIF (and other images) "File Handler", thus very uncontrolled method, has always been MS Paint. Not the best answer, but added here as the most basic Windows OS method.
Simply put you can mspaint /p a.gif
to the default printer (still works in Windows 10. Clearly a problem if your default is a PortPrompt (Easily fixed by set default to a different printer before invoking print)
So if you have a "Prompt less Port" copy of MS Print to PDF (Here it is A4 Landscape) then you can use the alternate "silent" (apart from a progress message box). PrintTo shell command.
mspaint /pt a.gif printername
Major disadvantage is, you need to fiddle registry settings to set margins and page print centering etc. So any other app should offer better printer control settings.
Upvotes: 0
Reputation: 4720
Check the printer you have. Some devices now have the ability to print gif, jpeg, tiff, etc. natively without requiring the conversion into PCL or PostScript datastreams (or other print language). If this is the case you could just send the file via the LPR protocol, directly over port 9100 or directly through a Windows print queue (http://support.microsoft.com/kb/322091)
Upvotes: 0
Reputation: 6188
I have bunch of 'gif' images. Your all links are for the .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();
}
}
Upvotes: 0
Reputation: 1129
An alternative method would be to programmatically create pdf document/s that you then batch print via CommandLine
Take a look at the iText library.
Once you have created your files, you can print them via a command line (you can using the Command class found in the System.Diagnostics namespace for that)
If you're doing all this from a batch, then you'll want to also be notified (perhaps programmatically) if something goes wrong with the print queue that you are printing to. I believe there is a class for that.
For more information on the subject, try here.
Upvotes: 1