簡體   English   中英

從C#窗口使用ReportViewer打印PDF

[英]Printing PDF using ReportViewer from C# windows

這是我創建的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。

我認為這篇MSDN文章為您的問題提供了很好的解決方案

通過以下鏈接有一些想法

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;
            }
        }

暫無
暫無

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

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