Unity 使用打印機打印

1,原文地址
只能打印圖片,需引用System.Drawing.dll

    /// <summary>
    /// 打印
    /// </summary>
    public void PrintFile()
    {
        PrintDocument pri = new PrintDocument();
        pri.PrintPage += Printpagetest;
        pri.Print();
    }

    private void Printpagetest(object sender, PrintPageEventArgs e)
    {
        try
        {
            System.Drawing.Image image = System.Drawing.Image.FromFile(printPath);
            System.Drawing.Graphics g = e.Graphics;
            g.TranslateTransform(_4AHeight, 0);
            g.RotateTransform(90);
            g.DrawImage(image, 0, 0, _4AWidth, _4AHeight);
        }
        catch (Exception ee)
        {
            Debug.LogError(ee.Message);
        }
    }

2,原文地址
可打印word、excel。

    public void PrintFile(string path)
    {
        System.Diagnostics.Process process = new System.Diagnostics.Process(); //系統(tǒng)進程
        process.StartInfo.CreateNoWindow = true; //不顯示調(diào)用程序窗口
        process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//
        process.StartInfo.UseShellExecute = true; //采用操作系統(tǒng)自動識別模式
        process.StartInfo.FileName = path; //要打印的文件路徑
        process.StartInfo.Verb = "print"; //指定執(zhí)行的動作,打?。簆rint 打開:open …………
        process.Start(); //開始打印    
    }

補充:在公司內(nèi)網(wǎng)測試時,無法打印,原因是沒有默認關聯(lián)程序,懷疑是word版本有問題,安裝wps并設為默認程序后,可正常打印。

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容