2013年8月22日 星期四

[學習] 利用ProcessStartInfo來列印

參考:
ProcessStartInfo 類別
ProcessStartInfo.Arguments 屬性
Sending byte array to printer
使用 C# 批次列印 PDF 檔案
[C#]使用預設印表機列印pdf文件
Try below code
Warning[] warnings;
      string  mimeType;
      string encoding;
      string extension;
      string deviceInfo;
      string[] streamids;
      deviceInfo =
       "<DeviceInfo>" +
       " <OutputFormat>PDF</OutputFormat>" +
       " <PageSize>A4</PageSize>" +
       " <PageWidth>8.5in</PageWidth>" +
       " <PageHeight>11in</PageHeight>" +
       " <MarginTop>0.25in</MarginTop>" +
       " <MarginLeft>0.25in</MarginLeft>" +
       " <MarginRight>0.25in</MarginRight>" +
       " <MarginBottom>0.25in</MarginBottom>" +
       "</DeviceInfo>";
      byte[] bytes  = ReportViewer1.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);  

FileStream fs = new FileStream(@"c:\output.PDF", 
        FileMode.Create);
      fs.Write(bytes, 0, bytes.Length);
      fs.Close();


ProcessStartInfo startInfo = new ProcessStartInfo();
      startInfo.UseShellExecute = true;
      startInfo.Verb = "Print";
      startInfo.Arguments = "Printer Name";
      startInfo.CreateNoWindow = false;
      startInfo.WindowStyle = ProcessWindowStyle.Hidden;
      startInfo.FileName = @"C:\output.pdf";
      Process p = new Process();
      p.StartInfo = startInfo;
      p.Start();

其它參考:

沒有留言:

張貼留言