简体   繁体   English

C#打印文件而不保存为PDF

[英]C# Print file Without saving as PDF

I am trying to print a simple receipt (text file), but when I do so my PC asks me to save the file (as PDF). 我正在尝试打印简单的收据(文本文件),但是当我这样做时,我的PC要求我保存文件(为PDF)。 Here is my code: 这是我的代码:

    private void btn_Pay_Click(object sender, EventArgs e) {
        //Button "Pay" clicked

        DialogResult result = MessageBox.Show("Print receipt?", "Success", MessageBoxButtons.YesNo);

        if (result == DialogResult.Yes) {
            //Print receipt

            ProcessStartInfo psi = new ProcessStartInfo(@"print.txt");
            psi.Verb = "PRINT";

            try {
                Process.Start(psi);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
    }

I don't want to save my text file (print.txt) as a pdf file I just want to print the text file. 我不想将文本文件(print.txt)保存为pdf文件,我只想打印文本文件。 (I don't have an actual printer connected to my computer, nor network, so I can't really print it, I just want to test it - not sure if that's an issue or not. The printer icon appeared in the bottom-right corner of my screen when I tried.) (我没有在计算机上连接实际的打印机,也没有网络,因此我无法真正打印它,我只想对其进行测试-不确定是否是问题。打印机图标出现在底部-尝试时在屏幕的右上角)。

Is there a way to get rid of the whole "save file (as pdf)"-process? 有没有一种方法可以摆脱整个“保存文件(如pdf)”过程?

If you don't have a printer the default function of windows is "Print to PDF".. The screenshot 如果你没有一台打印机窗口的默认功能是“打印到PDF” .. 截图

I think it is why it saves pdf. 我认为这就是为什么它可以保存pdf。 Try to connect the printer and set it as primary. 尝试连接打印机并将其设置为主打印机。

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

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