简体   繁体   English

如何在C#中打印存储在本地硬盘中的文件?

[英]How to print files stored at your local hard drive in C#?

I have a function created in C# (WinForms) which saves the file as gif image in local directory. 我有一个用C#(WinForms)创建的函数,将文件另存为gif图像在本地目录中。 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? 有什么帮助吗?

An alternative method would be to programmatically create pdf document/s that you then batch print via CommandLine 一种替代方法是以编程方式创建pdf文档,然后通过CommandLine批量打印

Take a look at the iText library. 看一下iText库。

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) 创建文件后,可以通过命令行打印它们(可以使用在System.Diagnostics命名空间中找到的Command类)。

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 . 有关此主题的更多信息,请尝试此处

I have bunch of 'gif' images. 我有一堆“ g​​if”图像。 Your all links are for the .txt files. 您的所有链接均适用于.txt文件。 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();

        }

    }

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). 现在,某些设备可以本地打印gif,jpeg,tiff等,而无需转换为PCL或PostScript数据流(或其他打印语言)。 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 ) 如果是这种情况,您可以直接通过LPR协议,直接通过端口9100或直接通过Windows打印队列发送文件( http://support.microsoft.com/kb/322091

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM