簡體   English   中英

當我們將默認瀏覽器設置為chrome(除IE之外)時,從Windows應用程序打印html文件不起作用

[英]Printing html file from windows application is not working when we set default browser as chrome (other than IE)

當我將默認瀏覽器設置為IE時,我必須在用戶點擊打印按鈕時打印html文件並且工作正常(提示打印對話框)。 如果我將默認瀏覽器更改為除IE之外的chrome或firefox,則代碼不會提示打印對話框,而只是在瀏覽器中打開html文件。 你可以告訴我在下面的代碼中我錯過了什么配置嗎?

            string TempFile = @"D:\test.html";    

            ProcessStartInfo Params = new ProcessStartInfo();
            Params.FileName = "iexplore.exe";
            Params.Arguments = TempFile;
            Params.UseShellExecute = false;
            Params.Verb = "print";
            Params.WindowStyle = ProcessWindowStyle.Hidden;
            Params.CreateNoWindow = true;
            Process.Start(Params);

最后我得到了這個問題的解決方案。 以下代碼就像一個魅力!

using (Process exeProcess = new Process())
{
    string TempFile = @"D:\test.html";
    exeProcess.StartInfo.FileName = "rundll32";
    exeProcess.StartInfo.Arguments = @"system32\mshtml.dll,PrintHTML """ + TempFile + @"""";
    exeProcess.StartInfo.UseShellExecute = true;
    exeProcess.Start();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM