How to Print any document in a SELECTED printer

ⅰ亾dé卋堺 提交于 2019-12-21 04:55:14

问题


I would like to print any document such as pdf,word,excel or text files in a selected printer using .net .I have got success to do such printing in the default printer .The only issue now is to print in the selected printer.

Here is the code for the printing.

public bool Print(string FilePath)
    {
        if (File.Exists(FilePath)) {
            if (ShellExecute((System.IntPtr )1, "Print", FilePath, "", Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32() <= 32) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

回答1:


Process printJob = new Process();
printJob.StartInfo.FileName = path;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printJob.StartInfo.Arguments = "\"" + printerAddress + "\"" + " " + printerExtraParameters;
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(path);
printJob.Start();



回答2:


What file format are you testing with success to the default printer?

Its not possible to just send "any" document to a printer, generally the specific file format needs to be interpretted by an application that can read the file format then render it to a printer or a file that can be interpretted by the printer.

In most cases if you can render to a PostScript or PDF you can get its to print using a single interpretter.



来源:https://stackoverflow.com/questions/3138181/how-to-print-any-document-in-a-selected-printer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!