水晶报表设置图片高度与宽度

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {//实例化水晶报表信息
                ReportDoc = new ReportDocument();
                logOnInfo = new TableLogOnInfo();
                FileOPS = new DiskFileDestinationOptions();
               //保存水晶报表图片传值的字典 
                dict = new Dictionary<string, string>();
            }
           
           //参数名:Picture4 值: c:\c.jpg
            dict.Add("Picture2", @"c:\c.jpg");
        
           //水晶报表的路径
            string ReportFile = Server.MapPath("CrystalReport2.rpt");
           //ReportDataSource 传递列表部分的内容 
            object ReportDataSource = null;
            string PDFFileName = Server.MapPath("test.pdf");
            ExportToPDF(ReportFile, ReportDataSource, PDFFileName, dict);
        }
        //生成PDF  ReportFile水晶报表路径  ReportDataSource列表 PDFFileName生成文件的路径 参数Filed Dictionary
        public bool ExportToPDF(string ReportFile, object ReportDataSource, string PDFFileName, Dictionary<string, string> dic)
        {
            try
            {
               //加载水晶报表
                ReportDoc.Load(ReportFile);
                if (ReportDataSource != null)
                {//列表
                    ReportDoc.SetDataSource(ReportDataSource);
                }
                if (dic != null)
                {//图片参数
                    foreach (KeyValuePair<string, string> str in dic)
                  {//获取图片、水晶报表控件并设置高度宽度
                        Bitmap image = new Bitmap(str.Value);
                        float x = image.VerticalResolution;
                      //  image.SetResolution(72, 72);
                        CrystalDecisions.CrystalReports.Engine.PictureObject tob = (CrystalDecisions.CrystalReports.Engine.PictureObject)ReportDoc.ReportDefinition.ReportObjects[str.Key];//获取图片控件
                        tob.Width = image.Width * 13;
                        tob.Height = image.Height * 13;
                    
                        image.Dispose();
                    }
                }
 
                FileOPS.DiskFileName = PDFFileName;
         
posted @ 2017-09-07 10:26  lzmaiyy  阅读(303)  评论(0编辑  收藏  举报