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并設為默認程序后,可正常打印。