如何打印任何文件中所选择的打印机 [英] How to Print any document in a SELECTED printer

查看:200
本文介绍了如何打印任何文件中所选择的打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印任何文件如PDF,词,用.NET。我已经得到成功的默认打印机。唯一的问题是现在在打印到做这样练成的印刷或文本文件中选择的打印机选定的打印机。



下面是打印的代码。

 公共BOOL打印(字符串文件路径)
{
如果(File.Exists(文件路径)){
如果(的ShellExecute((System.IntPtr)1,打印,文件路径,, Directory.GetDirectoryRoot(文件路径),SW_SHOWNORMAL).ToInt32()< = 32){
返回false;
}其他{
返回真;
}
}其他{
返回FALSE;
}
}


解决方案

 过程PRINTJOB =新工艺(); 
printJob.StartInfo.FileName =路径;
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(路径);
对PrintJob.start();


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;
        }
    }

解决方案

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();

这篇关于如何打印任何文件中所选择的打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆