【问题标题】:Printing PDF using ReportViewer from C# windows从 C# 窗口使用 ReportViewer 打印 PDF
【发布时间】:2015-06-17 23:25:16
【问题描述】:

这是我创建 PDF 的代码,它将打开 PDF 文档。

 public void createPDF(string Reportpath, ReportViewer RV)
        {
            Warning[] warnings;
            string[] streamids;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;

            byte[] bytes = RV.LocalReport.Render("pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
            try
            {
                FileStream fs = new FileStream(Reportpath, FileMode.Create);                    
                Thread.Sleep(1000);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
                Thread.Sleep(1000);
                System.Diagnostics.Process.Start(Reportpath); 
            }
            catch (Exception ex)
            {
                MessageBox.Show("Report could not be created...\n" + ex.Message);
            }
        }

我需要直接使用reportviewer或任何其他方式打印该pdf文档而不是打开pdf文件??。

【问题讨论】:

    标签: c# .net printing reportviewer


    【解决方案1】:

    我认为this MSDN article 可以很好地解决您的问题

    【讨论】:

      【解决方案2】:

      从以下链接得到一些想法

      http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and

      将pdf发送到adobe reader打印....

      public static Boolean PrintPDFs(string pdfFileName)
              {
                  try
                  {
                      Process proc = new Process();
                      proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                      proc.StartInfo.Verb = "print";
      
                      //Define location of adobe reader/command line
                      //switches to launch adobe in "print" mode
                      proc.StartInfo.FileName = 
                        @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
                      proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
                      proc.StartInfo.UseShellExecute = false;
                      proc.StartInfo.CreateNoWindow = true;
      
                      proc.Start();
                      proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                      if (proc.HasExited == false)
                      {
                          proc.WaitForExit(10000);
                      }
      
                      proc.EnableRaisingEvents = true;
      
                      proc.Close();
                      KillAdobe("AcroRd32");
                      return true;
                  }
                  catch
                  {
                      return false;
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 2011-09-18
        • 2014-06-23
        • 2014-08-09
        • 2018-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-07
        相关资源
        最近更新 更多