public void Export(LocalReport report, Dictionary <string, double> size = null) { string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.25in</MarginTop>" + " <MarginLeft>0.25in</MarginLeft>" + " <MarginRight>0.25in</MarginRight>" + " <MarginBottom>0.25in</MarginBottom>" + "</DeviceInfo>"; if ((size != null)) { Console.WriteLine("Resizing Paper...."); string paperWidth_in = size["width"].ToString("0.00"); string paperHeight_in = size["height"].ToString("0.00"); deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + " <PageWidth>" + paperWidth_in + "in</PageWidth>" + " <PageHeight>" + paperHeight_in + "in</PageHeight>" + " <MarginTop>0.25in</MarginTop>" + " <MarginLeft>0.25in</MarginLeft>" + " <MarginRight>0.25in</MarginRight>" + " <MarginBottom>0.25in</MarginBottom>" + "</DeviceInfo>"; } Console.WriteLine("Device Info:"); Console.WriteLine(deviceInfo); Warning[] warnings = null; m_streams = new List <Stream>(); report.Refresh(); report.Render("Image", deviceInfo, CreateStream, out warnings); Console.WriteLine(report.GetDefaultPageSettings().PaperSize); Console.WriteLine(report.GetDefaultPageSettings().Margins); Stream stream = null; foreach (Stream stream_loopVariable in m_streams) { stream = stream_loopVariable; stream.Position = 0; } }
public void Print() { LocalReport report = new LocalReport(); report.ReportPath = reportName; report.DataSources.Add(new ReportDataSource("DataSet1", sourceData)); if (Parameters.Count > 0) { foreach (DictionaryEntry de in Parameters) { ReportParameter rptPara = new ReportParameter(de.Key.ToString(), de.Value.ToString()); report.SetParameters(new ReportParameter[] { rptPara }); } } report.Refresh(); string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + //" <PageWidth>8.27in</PageWidth>" + //" <PageHeight>5in</PageHeight>" + // " <MarginTop>0.1in</MarginTop>" + // " <MarginLeft>0.1in</MarginLeft>" + // " <MarginRight>0.1in</MarginRight>" + // " <MarginBottom>0.1in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; m_streams = new List <Stream>(); report.Render("Image", deviceInfo, CreateStream, out warnings); //Export(report); string printname = new PrintDocument().PrinterSettings.PrinterName; m_currentPageIndex = 0; if (m_streams == null || m_streams.Count == 0) { return; } PrintDocument printDoc = new PrintDocument(); printDoc.PrinterSettings.PrinterName = printerName; if (!printDoc.PrinterSettings.IsValid) { MessageBox.Show("Can't find printer"); return; } printDoc.PrintPage += new PrintPageEventHandler(PrintPage); //指定是否横向打印 printDoc.DefaultPageSettings.Landscape = false; //将RDLC报表上的参数传递过来 //printDoc.DefaultPageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape; printDoc.DefaultPageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize; printDoc.DefaultPageSettings.Margins = report.GetDefaultPageSettings().Margins; printDoc.Print(); }
public static void Print(this LocalReport report) { var pageSettings = new PageSettings(); pageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize; pageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape; pageSettings.Margins = report.GetDefaultPageSettings().Margins; Print(report, pageSettings); }
public static void PrintToPrinter(this LocalReport report) { MessageBox.Show(report.GetDefaultPageSettings().PaperSize.Height.ToString()); PageSettings pageSettings = new PageSettings(); pageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize; pageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape; pageSettings.Margins = report.GetDefaultPageSettings().Margins; Print(report, pageSettings); }
protected void executeReport_click(object sender, EventArgs e) { if (reportSelector.SelectedIndex == 9) executeReportInAppDomain_click(sender, e); else { LocalReport rpt = new LocalReport(); rpt.EnableExternalImages = true; rpt.ReportPath = String.Concat(Path.GetDirectoryName(Request.PhysicalPath), "\\Reports\\", reportSelector.SelectedValue); string orientation = (rpt.GetDefaultPageSettings().IsLandscape) ? "landscape" : "portrait"; StringReader formattedReport = Business.reportHelper.FormatReportForTerritory(rpt.ReportPath, orientation, cultureSelector.SelectedValue); rpt.LoadReportDefinition(formattedReport); // Add Data Source rpt.DataSources.Add(new ReportDataSource("InvoiceDataTable", dt)); // Internationlisation: Add uiCulture and Translation Labels if (reportSelector.SelectedIndex >= 3) { Dictionary<string, string> reportLabels = Reports.reportTranslation.translateInvoice(cultureSelector.SelectedValue); ReportParameterCollection reportParams = new ReportParameterCollection(); reportParams.Add(new ReportParameter("uiCulture", cultureSelector.SelectedValue)); foreach (string key in reportLabels.Keys) reportParams.Add(new ReportParameter(key, reportLabels[key])); rpt.SetParameters(reportParams); } // Render To Browser renderPDFToBrowser(rpt.Render("PDF", Business.reportHelper.GetDeviceInfoFromReport(rpt, cultureSelector.SelectedValue, "PDF"))); } }
public LocalReportPrinter(string reportFullPath, PaperSize paperSize = null) { _reportFullPath = Application.StartupPath + @"\" + reportFullPath; _report = new LocalReport { ReportPath = _reportFullPath }; _paperSize = paperSize ?? _report.GetDefaultPageSettings().PaperSize; _streams = new List<Stream>(); }
/// <summary> /// 为Report.rdlc创建本地报告加载数据,输出报告到.emf文件,并打印,同时释放资源 /// </summary> /// <param name="rv">参数:ReportViewer.LocalReport</param> public void PrintStream(LocalReport rvDoc) { //获取LocalReport中的报表页面方向 isLandSapces = rvDoc.GetDefaultPageSettings().IsLandscape; Export(rvDoc); PrintSetting(); DisposeObject(); }
public LocalReportPrinter(string reportFullPath, PaperSize paperSize = null) { _reportFullPath = Application.StartupPath + @"\" + reportFullPath; _report = new LocalReport { ReportPath = _reportFullPath }; _paperSize = paperSize ?? _report.GetDefaultPageSettings().PaperSize; _streams = new List <Stream>(); }
public static void PrintToPrinter(this LocalReport report) { m_pageSettings = new PageSettings(); ReportPageSettings reportPageSettings = report.GetDefaultPageSettings(); m_pageSettings.PaperSize = reportPageSettings.PaperSize; m_pageSettings.Margins = reportPageSettings.Margins; Export(report); }
/* * public static void Print(this LocalReport report, PageSettings pageSettings) * { * string deviceInfo = * $@"<DeviceInfo> * <OutputFormat>EMF</OutputFormat> * <PageWidth>{pageSettings.PaperSize.Width * 100}in</PageWidth> * <PageHeight>{pageSettings.PaperSize.Height * 100}in</PageHeight> * <MarginTop>{pageSettings.Margins.Top * 100}in</MarginTop> * <MarginLeft>{pageSettings.Margins.Left * 100}in</MarginLeft> * <MarginRight>{pageSettings.Margins.Right * 100}in</MarginRight> * <MarginBottom>{pageSettings.Margins.Bottom * 100}in</MarginBottom> * </DeviceInfo>"; * * Warning[] warnings; * var streams = new List<Stream>(); * var currentPageIndex = 0; * * report.Render("Image", deviceInfo, * (name, fileNameExtension, encoding, mimeType, willSeek) => * { * var stream = new MemoryStream(); * streams.Add(stream); * return stream; * }, out warnings); * * foreach (Stream stream in streams) * stream.Position = 0; * * if (streams == null || streams.Count == 0) * throw new Exception("Error: no stream to print."); * * var printDocument = new PrintDocument(); * printDocument.DefaultPageSettings = pageSettings; * if (!printDocument.PrinterSettings.IsValid) * throw new Exception("Error: cannot find the default printer."); * else * { * printDocument.PrintPage += (sender, e) => * { * Metafile pageImage = new Metafile(streams[currentPageIndex]); * Rectangle adjustedRect = new Rectangle( * e.PageBounds.Left - (int)e.PageSettings.HardMarginX, * e.PageBounds.Top - (int)e.PageSettings.HardMarginY, * e.PageBounds.Width, * e.PageBounds.Height); * e.Graphics.FillRectangle(Brushes.White, adjustedRect); * e.Graphics.DrawImage(pageImage, adjustedRect); * currentPageIndex++; * e.HasMorePages = (currentPageIndex < streams.Count); * e.Graphics.DrawRectangle(Pens.Red, adjustedRect); * }; * printDocument.EndPrint += (Sender, e) => * { * if (streams != null) * { * foreach (Stream stream in streams) * stream.Close(); * streams = null; * } * }; * printDocument.Print(); * } * } * */ private void Export(LocalReport report) { /* * var pageSettings = new PageSettings(); * pageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize; * pageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape; * pageSettings.Margins = report.GetDefaultPageSettings().Margins; * Print(report, pageSettings); * string deviceInfo = * $@"<DeviceInfo> * <OutputFormat>EMF</OutputFormat> * <PageWidth>{pageSettings.PaperSize.Width * 100}in</PageWidth> * <PageHeight>{pageSettings.PaperSize.Height * 100}in</PageHeight> * <MarginTop>{pageSettings.Margins.Top * 100}in</MarginTop> * <MarginLeft>{pageSettings.Margins.Left * 100}in</MarginLeft> * <MarginRight>{pageSettings.Margins.Right * 100}in</MarginRight> * <MarginBottom>{pageSettings.Margins.Bottom * 100}in</MarginBottom> * </DeviceInfo>"; */ string deviceInfo = // @"<DeviceInfo> // <OutputFormat>EMF</OutputFormat> // <PageWidth>7cm</PageWidth> // <PageHeight>8in</PageHeight> // <MarginTop>0in</MarginTop> // <MarginLeft>0in</MarginLeft> // <MarginRight>0in</MarginRight> // <MarginBottom>0in</MarginBottom> //</DeviceInfo>"; //@"<DeviceInfo> // <OutputFormat>EMF</OutputFormat> // <PageWidth>276</PageWidth> // <PageHeight>600</PageHeight> // <MarginTop>0</MarginTop> // <MarginLeft>0</MarginLeft> // <MarginRight>0</MarginRight> // <MarginBottom>0</MarginBottom> //</DeviceInfo>"; @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> </DeviceInfo>"; Warning[] warnings; m_streams = new List <Stream>(); var ps = report.GetDefaultPageSettings(); report.Render("Image", deviceInfo, CreateStream, out warnings); //report.Render("Image"); foreach (Stream stream in m_streams) { stream.Position = 0; } }
private void Export(LocalReport report) { //这里是设置打印的格式 边距什么的 double width = Convert.ToDouble(report.GetDefaultPageSettings().PaperSize.Width) / 25.4; double height = Convert.ToDouble(report.GetDefaultPageSettings().PaperSize.Height) / 25.4; //string deviceInfo = // "<DeviceInfo>" + // " <OutputFormat>EMF</OutputFormat>" + // " <PageWidth>"+width+"mm</PageWidth>" + // " <PageHeight>"+height+"mm</PageHeight>" + // " <MarginTop>5mm</MarginTop>" + // " <MarginLeft>2mm</MarginLeft>" + // " <MarginRight>2mm</MarginRight>" + // " <MarginBottom>5mm</MarginBottom>" + // "</DeviceInfo>"; string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + "</DeviceInfo>"; Warning[] warnings; m_streams = new List <Stream>(); try { report.Render("Image", deviceInfo, CreateStream, out warnings);//一般情况这里会出错的 使用catch得到错误原因 一般都是简单错误 } catch (Exception ex) { Exception innerEx = ex.InnerException;//取内异常。因为内异常的信息才有用,才能排除问题。 while (innerEx != null) { //MessageBox.Show(innerEx.Message); string errmessage = innerEx.Message; innerEx = innerEx.InnerException; } } foreach (Stream stream in m_streams) { stream.Position = 0; } }
//public AutoPrintCls(ServerReport serverReport) // : this((Report)serverReport) //{ // RenderAllServerReportPages(serverReport); //} //public AutoPrintCls(LocalReport localReport) // : this((Report)localReport) //{ // RenderAllLocalReportPages(localReport); //} private AutoPrintCls(LocalReport report) { // Set the page settings to the default defined in the report ReportPageSettings reportPageSettings = report.GetDefaultPageSettings(); // The page settings object will use the default printer unless // PageSettings.PrinterSettings is changed. This assumes there // is a default printer. m_pageSettings = new PageSettings(); m_pageSettings.PaperSize = reportPageSettings.PaperSize; m_pageSettings.Margins = reportPageSettings.Margins; }
public static string GetDeviceInfo(LocalReport localReport) { //Body Width <= Page Width - (Left Margin + Right Margin) //Horizontal usable area: //X = Page.Width - (Left Margin + Right Margin + Column Spacing) //Vertical usable area: //Y = Page.Height - (Top Margin + Bottom Margin + Header Height + Footer Height) string deviceInfo = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + string.Format(" <PageWidth>{0}in</PageWidth>", ((decimal)(localReport.GetDefaultPageSettings().PaperSize.Width) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + string.Format(" <PageHeight>{0}in</PageHeight>", ((decimal)(localReport.GetDefaultPageSettings().PaperSize.Height) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + string.Format(" <MarginTop>{0}in</MarginTop>", ((decimal)(localReport.GetDefaultPageSettings().Margins.Top) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + string.Format(" <MarginLeft>{0}in</MarginLeft>", ((decimal)(localReport.GetDefaultPageSettings().Margins.Left) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + string.Format(" <MarginRight>{0}in</MarginRight>", ((decimal)(localReport.GetDefaultPageSettings().Margins.Right) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + string.Format(" <MarginBottom>{0}in</MarginBottom>", ((decimal)(localReport.GetDefaultPageSettings().Margins.Bottom) / 100).ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))) + "</DeviceInfo>"; return(deviceInfo); }
public static void Export(LocalReport report, bool print = true) { try { var pageSettings = new PageSettings(); pageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize; pageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape; pageSettings.Margins = report.GetDefaultPageSettings().Margins; string deviceInfo = @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>{pageSettings.PaperSize.Width}in</PageWidth> <PageHeight>{pageSettings.PaperSize.Height}in</PageHeight> <MarginTop>{pageSettings.Margins.Top}in</MarginTop> <MarginLeft>{pageSettings.Margins.Left}in</MarginLeft> <MarginRight>{pageSettings.Margins.Right}in</MarginRight> <MarginBottom>{pageSettings.Margins.Bottom}in</MarginBottom> </DeviceInfo>"; Warning[] warnings; m_streams = new List <Stream>(); report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams) { stream.Position = 0; } if (print) { Print(); } } catch (Exception e) { MessageBox.Show(e.Message); } }
public static string GetDeviceInfoFromReport(LocalReport rpt, string uiCulture, string format) { string strMargins; string orientation; //Render overwrites margins defined in RDLC; capture margins in RDLC ReportPageSettings pageSettings = rpt.GetDefaultPageSettings(); strMargins = String.Concat((Convert.ToDouble(pageSettings.Margins.Top) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Left) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Bottom) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Right) / 40.0).ToString()); //Capture report orientation orientation = pageSettings.IsLandscape ? "landscape" : "portrait"; return GetDeviceInfo(uiCulture, format, strMargins, orientation); }
private static string PrepareAndGetDeviceInfo(LocalReport report, ReportSettings settings) { //var customAssemblyName = "Greewf.BaseLibrary, Culture=neutral, PublicKeyToken=ebf2eb006a1f561b"; //var customAssembly = Assembly.Load(customAssemblyName); //StrongName assemblyStrongName = CreateStrongName(customAssembly); //report.AddFullTrustModuleInSandboxAppDomain(assemblyStrongName); //it seems that the following lines do not need anymore becuase of code sigining. In test senario, it doesn't affect performance. PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted); report.SetBasePermissionsForSandboxAppDomain(permissions); var defaults = report.GetDefaultPageSettings(); var marginTop = settings.TopMargin.HasValue ? (settings.TopMargin * (1 / 2.54)) : defaults.Margins.Top / 100.0; var marginBottom = settings.BottomMargin.HasValue ? (settings.BottomMargin * (1 / 2.54)) : defaults.Margins.Bottom / 100.0; var marginLeft = settings.LeftMargin.HasValue ? (settings.LeftMargin * (1 / 2.54)) : defaults.Margins.Left / 100.0; var marginRight = settings.RightMargin.HasValue ? (settings.RightMargin * (1 / 2.54)) : defaults.Margins.Right / 100.0; settings.EndPage = settings.EndPage ?? settings.StartPage; //The DeviceInfo settings should be changed based on the reportType // http://msdn2.microsoft.com/en-us/library/ms155397.aspx // http://msdn.microsoft.com/en-us/library/hh231593.aspx string deviceInfo = "<DeviceInfo>" + ((settings.DpiX > 0) ? " <DpiX>" + settings.DpiX + "</DpiX>" : "") + ((settings.DpiY > 0) ? " <DpiY>" + settings.DpiY + "</DpiY>" : "") + " <OutputFormat>" + settings.OutputType + "</OutputFormat>" + " <PageWidth>" + (defaults.IsLandscape ? defaults.PaperSize.Height : defaults.PaperSize.Width) / 100.0 + "in</PageWidth>" + " <PageHeight>" + (defaults.IsLandscape ? defaults.PaperSize.Width : defaults.PaperSize.Height) / 100.0 + "in</PageHeight>" + " <MarginTop>" + marginTop + "in</MarginTop>" + " <MarginLeft>" + marginLeft + "in</MarginLeft>" + " <MarginRight>" + marginRight + "in</MarginRight>" + " <MarginBottom>" + marginBottom + "in</MarginBottom>" + " <StartPage>" + (settings.StartPage ?? 0) + "</StartPage>" + " <EndPage>" + (settings.EndPage ?? 0) + "</EndPage>" + " <PageBreaksMode>OnEachPage</PageBreaksMode>" + " <HumanReadablePDF>" + settings.HumanReadablePdf.ToString() + "</HumanReadablePDF>"; if (!settings.EmbedFontsInPdf) { deviceInfo += " <EmbedFonts>None</EmbedFonts>"; } deviceInfo += "</DeviceInfo>"; return(deviceInfo); }
public static string GetDeviceInfoFromReport(LocalReport rpt, string uiCulture, string format) { string strMargins; string orientation; //Render overwrites margins defined in RDLC; capture margins in RDLC ReportPageSettings pageSettings = rpt.GetDefaultPageSettings(); strMargins = String.Concat((Convert.ToDouble(pageSettings.Margins.Top) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Left) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Bottom) / 40.0).ToString(), ",", (Convert.ToDouble(pageSettings.Margins.Right) / 40.0).ToString()); //Capture report orientation orientation = pageSettings.IsLandscape ? "landscape" : "portrait"; return(GetDeviceInfo(uiCulture, format, strMargins, orientation)); }
/// <summary> /// /// </summary> /// <param name="localReport"></param> public ReportPrintDocument(LocalReport localReport) { // Set the page settings to the default defined in the report ReportPageSettings reportPageSettings = localReport.GetDefaultPageSettings(); // The page settings object will use the default printer unless // PageSettings.PrinterSettings is changed. This assumes there // is a default printer. m_pageSettings = new PageSettings(); m_pageSettings.PaperSize = reportPageSettings.PaperSize; m_pageSettings.Margins = reportPageSettings.Margins; RenderAllLocalReportPages(localReport); }
private void Export(LocalReport report) { report.EnableExternalImages = true; ReportPageSettings rps = report.GetDefaultPageSettings(); ps = rps.PaperSize; ms = rps.Margins; isLandscape = rps.IsLandscape; Width = ps.Width; Height = ps.Height; if (rps.IsLandscape) { Width = ps.Height; Height = ps.Width; } int totalPages = 1; Warning[] warnings; string deviceInfo; do { this.Dispose(); m_streams = new List <Stream>(); deviceInfo = @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>" + Width / 100.00 + "in</PageWidth>" + "<PageHeight>" + Height / 100.00 + "in</PageHeight>" + "<MarginTop>" + ms.Top / 100.00 + "in</MarginTop>" + "<MarginLeft>" + ms.Left / 100.00 + "in</MarginLeft>" + "<MarginRight>" + ms.Right / 100.00 + "in</MarginRight>" + "<MarginBottom>" + ms.Bottom / 100.00 + "in</MarginBottom>" + "</DeviceInfo>"; report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams) { stream.Position = 0; } totalPages = m_streams.Count; if (totalPages > 1) { Height += 29; } }while (totalPages > 1); }
/// <summary> /// /// </summary> /// <param name="report"></param> /// <param name="printerName"></param> public void Run(LocalReport report, string printerName, bool landscape) { //LocalReport report = new LocalReport(); //report.ReportPath = reportPath;//加上报表的路径 //report.DataSources.Add(new ReportDataSource(dt1SourceName, dt1)); //report.DataSources.Add(new ReportDataSource(dt2SourceName, dt2)); //report.EnableExternalImages = true; //ReportParameter rp = new ReportParameter("isHindeLogoImg", isHindeLogo.ToString());//这里我在报表里弄的参数 //report.SetParameters(rp); //report.GetDefaultPageSettings().PaperSize.h Export(report); m_currentPageIndex = 0; landscape = report.GetDefaultPageSettings().IsLandscape; Print(printerName, landscape); }
public byte[] Render(ReportName reportName, IDictionary<string, object[]> dataSources, params ReportParameter[] parameters) { var localReport = new LocalReport(); localReport.ReportEmbeddedResource = new ReportResourceResolver().ResolveResource(reportName); foreach (var dataSource in dataSources) { var reportDataSource = new ReportDataSource(dataSource.Key, dataSource.Value); localReport.DataSources.Add(reportDataSource); } if (parameters != null && parameters.Length > 0) localReport.SetParameters(parameters); var reportType = "PDF"; var settings = localReport.GetDefaultPageSettings(); var width = settings.IsLandscape ? settings.PaperSize.Height : settings.PaperSize.Width; var height = settings.IsLandscape ? settings.PaperSize.Width : settings.PaperSize.Height; var deviceInfo = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + " <PageWidth>" + width / 100.0m + "in</PageWidth>" + " <PageHeight>" + height / 100.0m + "in</PageHeight>" + " <MarginTop>" + settings.Margins.Top / 100.0m + "in</MarginTop>" + " <MarginLeft>" + settings.Margins.Left / 100.0m + "in</MarginLeft>" + " <MarginRight>" + settings.Margins.Right / 100.0m + "in</MarginRight>" + " <MarginBottom>" + settings.Margins.Bottom / 100.0m + "in</MarginBottom>" + "</DeviceInfo>"; string mimeType; string encoding; string fileNameExtension; Warning[] warnings; string[] streams; return localReport.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); }
private string Export(LocalReport localReport) { PageSettings pageSettings = new PageSettings(); var settings = localReport.GetDefaultPageSettings(); string deviceInfo = $@"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>{settings.PaperSize.Width * 100}in</PageWidth> <PageHeight>{settings.PaperSize.Height * 100}in</PageHeight> <MarginTop>{settings.Margins.Top * 100}in</MarginTop> <MarginLeft>{settings.Margins.Left * 100}in</MarginLeft> <MarginRight>{settings.Margins.Right * 100}in</MarginRight> <MarginBottom>{settings.Margins.Bottom * 100}in</MarginBottom> </DeviceInfo>"; return(deviceInfo); }
protected void executeReport_click(object sender, EventArgs e) { if (reportSelector.SelectedIndex == 9) { executeReportInAppDomain_click(sender, e); } else { LocalReport rpt = new LocalReport(); rpt.EnableExternalImages = true; rpt.ReportPath = String.Concat(Path.GetDirectoryName(Request.PhysicalPath), "\\Reports\\", reportSelector.SelectedValue); string orientation = (rpt.GetDefaultPageSettings().IsLandscape) ? "landscape" : "portrait"; StringReader formattedReport = Business.reportHelper.FormatReportForTerritory(rpt.ReportPath, orientation, cultureSelector.SelectedValue); rpt.LoadReportDefinition(formattedReport); // Add Data Source rpt.DataSources.Add(new ReportDataSource("InvoiceDataTable", dt)); // Internationlisation: Add uiCulture and Translation Labels if (reportSelector.SelectedIndex >= 3) { Dictionary <string, string> reportLabels = Reports.reportTranslation.translateInvoice(cultureSelector.SelectedValue); ReportParameterCollection reportParams = new ReportParameterCollection(); reportParams.Add(new ReportParameter("uiCulture", cultureSelector.SelectedValue)); foreach (string key in reportLabels.Keys) { reportParams.Add(new ReportParameter(key, reportLabels[key])); } rpt.SetParameters(reportParams); } // Render To Browser renderPDFToBrowser(rpt.Render("PDF", Business.reportHelper.GetDeviceInfoFromReport(rpt, cultureSelector.SelectedValue, "PDF"))); } }
public byte[] ConvertToPdf(LocalReport report) { var defaults = report.GetDefaultPageSettings(); //The DeviceInfo settings should be changed based on the reportType //http://msdn2.microsoft.com/en-us/library/ms155397.aspx string deviceInfo = "<DeviceInfo>" + " <OutputFormat>PDF</OutputFormat>" + " <PageWidth>" + defaults.PaperSize.Width / 100.0 + "in</PageWidth>" + " <PageHeight>" + defaults.PaperSize.Height / 100.0 + "in</PageHeight>" + " <MarginTop>" + defaults.Margins.Top / 100.0 + "in</MarginTop>" + " <MarginLeft>" + defaults.Margins.Left / 100.0 + "in</MarginLeft>" + " <MarginRight>" + defaults.Margins.Right / 100.0 + "in</MarginRight>" + " <MarginBottom>" + defaults.Margins.Bottom / 100.0 + "in</MarginBottom>" + "</DeviceInfo>"; byte[] renderedBytes; //Render the report renderedBytes = report.Render("PDF", deviceInfo); return(renderedBytes); }
public static void ExportTo <T>(this T ds, string ReportName, FileType filetype, ReportParameterCollection parameters = null) where T : DataSet, new() { string contentType = "application/pdf"; string header = "attachment; filename=exportado.pdf"; string reportType = "PDF"; string mimeType; string encoding; string fileNameExtension; Warning[] warnings; string[] streams; byte[] bytes; if (filetype == FileType.Excel) { reportType = "Excel"; header = "attachment;filename=exportado.xls"; contentType = "application/ms-excel"; } HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); HttpContext.Current.Response.ContentType = contentType; HttpContext.Current.Response.AddHeader("Content-Disposition", header); LocalReport relatorio = new LocalReport(); relatorio.ReportPath = HttpContext.Current.Server.MapPath(string.Format("~/Report/{0}.rdlc", ReportName)); relatorio.EnableExternalImages = true; relatorio.EnableHyperlinks = true; PaperSize reportPgSize = null; try { reportPgSize = relatorio.GetDefaultPageSettings().PaperSize; } catch (Exception ex) { throw ex; } var pgsize = relatorio.GetDefaultPageSettings(); pgsize.PaperSize.RawKind = (int)PaperKind.A4; PaperSize paperSize = reportPgSize ?? pgsize.PaperSize; Margins margins = pgsize.Margins; margins.Top = 0; margins.Bottom = 0; margins.Left = 0; margins.Right = 0; string deviceInfo = string.Format( CultureInfo.InvariantCulture, "<DeviceInfo>" + "<MarginTop>{0}</MarginTop>" + "<MarginLeft>{1}</MarginLeft>" + "<MarginRight>{2}</MarginRight>" + "<MarginBottom>{3}</MarginBottom>" + "<PageHeight>{4}</PageHeight>" + "<PageWidth>{5}</PageWidth>" + "</DeviceInfo>", ToInches(margins.Top), ToInches(margins.Left), ToInches(margins.Right), ToInches(margins.Bottom), ToInches(pgsize.IsLandscape ? paperSize.Width : paperSize.Height), ToInches(pgsize.IsLandscape ? paperSize.Height : paperSize.Width)); relatorio.DataSources.Clear(); if (ds != null) { if (ds.Tables.Count > 0) { foreach (DataTable tb in ds.Tables) { ReportDataSource source = new ReportDataSource(); source.Name = tb.TableName; source.Value = tb; relatorio.DataSources.Add(source); } } } if (parameters != null) { foreach (var parameter in parameters) { relatorio.SetParameters(parameter); } } //Renderiza o relatório em bytes bytes = relatorio.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); HttpContext.Current.Response.BinaryWrite(bytes); HttpContext.Current.Response.End(); }
/// <summary> /// Get the default printer /// </summary> /// <returns></returns> public PrintDocument GetDefaultPrinter() { //obtien le nombre de page du rapport BitmapDecoder dec = GetImage(); PrintDocument pDoc = new PrintDocument(); pDoc.DefaultPageSettings.Landscape = this._report.GetDefaultPageSettings().IsLandscape; pDoc.DefaultPageSettings.PaperSize = new PaperSize(this._report.GetDefaultPageSettings().PaperSize.PaperName, _report.GetDefaultPageSettings().PaperSize.Width, _report.GetDefaultPageSettings().PaperSize.Height); //par default ont imprime toute les pages pDoc.PrinterSettings.FromPage = 1; pDoc.PrinterSettings.ToPage = dec.Frames.Count; return(pDoc); }
public ActionResult BillServicesAssign_Printing(string type, int repID) { LocalReport locRep = new LocalReport(); string path = Path.Combine(Server.MapPath("~/Reportor/"), "BillServicesAssign_Printing.rdlc"); System.Diagnostics.Debug.WriteLine("TEST PATH FILE :" + path); if (System.IO.File.Exists(path)) { locRep.ReportPath = path; } else { return(Redirect("~/Services")); } Database db = new Database(); RepairDAO repDAO = new RepairDAO(db); RepairModel repModel = repDAO.FindById(repID); db.Close(); ReportParameter[] pr = new ReportParameter[] { new ReportParameter("CDETAIL", repModel.CUSTOMER.C_NAME + " " + repModel.CUSTOMER.C_LASTNAME + (!repModel.CUSTOMER.C_TEL.Equals("")?" เบอร์โทร : " + repModel.CUSTOMER.C_TEL:" ") + (!repModel.CUSTOMER.C_ADDRESS.Equals("")?" ที่อยู่ : " + repModel.CUSTOMER.C_ADDRESS:" ")), new ReportParameter("STAFF", repModel.STAFF.NAME + " " + repModel.STAFF.LASTNAME), new ReportParameter("PRODUCT", repModel.PRODUCT.TYPE.PRO_TYPE_NAME + " " + repModel.PRODUCT.BANRD.PRO_BAND_NAME + " " + repModel.MODEL + " " + repModel.COLOR), new ReportParameter("DAMAGE", repModel.DAMAGE), new ReportParameter("ASSIGN_DATE", repModel.DATE_ASSIGN), new ReportParameter("CONSIGN_DATE", repModel.DATE_CONSIGN.ToString()), new ReportParameter("RECIPIENT", repModel.RECIPIENT_ID.NAME + " " + repModel.RECIPIENT_ID.LASTNAME), new ReportParameter("REPID", repModel.REPAIR_NO.ToString()) }; locRep.SetParameters(pr); locRep.GetDefaultPageSettings(); locRep.DisplayName = repModel.REPAIR_NO.ToString(); string reportType = type; string mimeType; string encoding; string fileNameExtension; string deviceInfoA4 = "<DeviceInfo>" + " <OutputFormat>" + type + "</OutputFormat>" + " <PageWidth>17.78cm</PageWidth>" + " <PageHeight>12.7cm</PageHeight>" + " <MarginTop>1cm</MarginTop>" + " <MarginLeft>0.5in</MarginLeft>" + " <MarginRight>0.5in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = locRep.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return(File(renderedBytes, mimeType)); }
public ActionResult GetPDF() { //Response.StatusCode = 400; //Response.End(); int id = Convert.ToInt32(queryValues["id"]); DataTable dt = GetData(id); DataTable dtDetail = GetDetail(id); LocalReport lr = new LocalReport(); lr.DataSources.Clear(); lr.DataSources.Add(new ReportDataSource("dsReciboViaje", dt)); lr.DataSources.Add(new ReportDataSource("dsFileReciboViajeItemDetail", dtDetail)); lr.ReportPath = "bin/Areas/Reports/ReportDesign/ReciboViaje.rdlc"; //lr.SubreportProcessing += new SubreportProcessingEventHandler(lr_SubreportProcessing); string reportType = "PDF"; string mimeType; string encoding; string fileNameExtension; //ReportPageSettings rps = lr.GetDefaultPageSettings(); LogManager.Write(lr.GetDefaultPageSettings().PaperSize.PaperName); string deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + id + "</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.2in</MarginTop>" + " <MarginLeft>0.2in</MarginLeft>" + " <MarginRight>0.2in</MarginRight>" + " <MarginBottom>0.2in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = lr.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); //Response.ContentType = "application/pdf"; //Response.AddHeader("content-length", renderedBytes.Length.ToString()); //Response.AddHeader("Content-Disposition:attachment", "inline;"); //Response.AddHeader("Cache-Control", "private, max-age=0, must-revalidate"); //Response.AddHeader("Pragma", "public"); //Response.BinaryWrite(renderedBytes); //Response.Clear(); //Response.ContentType = "application/pdf"; //Response.BinaryWrite(renderedBytes); //Response.Flush(); //Response.End(); return(File(renderedBytes, mimeType)); //return renderedBytes; //return View(); }
private static string PrepareAndGetDeviceInfo(LocalReport report, ReportSettings settings) { /* * برای افزایش سرعت در حالت سندباکس کارهای زیاد انجام دادیم ولی نشد. * توجه!!!!! خیلی جالب آنکه اجرا در لوکال از سرور های تست * خیلی سریعتیر است اما بعد از پابلیش در سرور همچنان کند است * * کارهای زیر انجام شد : * * ----------------------------- کار 1 -------------------------------------------------------------- * * کد زیر دقیقا در همین تابع و در همین ابندای آن قرار داده شد. کد کار می کند ولی تاثیری در سرعت نداشت : * * * PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted); * permissions.AddPermission(new SecurityPermission(PermissionState.Unrestricted)); * permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags)); * permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); * permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); * * report.SetBasePermissionsForSandboxAppDomain(permissions); * * var customAssembly = typeof(ReportsLoader).Assembly;// "Greewf.Reporting, Culture=neutral, PublicKeyToken=ebf2eb006a1f561b"; * StrongName assemblyStrongName = CreateStrongName(customAssembly); * report.AddFullTrustModuleInSandboxAppDomain(assemblyStrongName); * * * * ----------------------------- کار 2 -------------------------------------------------------------- * * همچنین تنظیمات زیر را هم در وب کانفیگ پروژه اجرایی گذاشتیم ولی باز تاثیری نداشت : * این موارد طبق این پست ها بود : https://stackoverflow.com/a/26733816/790811 & https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ee191568(v=vs.100) * * در بخش configuration: * * <startup uselegacyv2runtimeactivationpolicy="true"> * </startup> * * و در بخش runtime: * <NetFx40_LegacySecurityPolicy enabled="true" /> * * * همچنین در اینجا یک پست هست که توضیح با بالاترین ووت هم خواندنی است : https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6d89e2ce-3528-465f-9740-7e22aa7b7aae/slow-performance-with-dynamic-grouping-and-reportviewer-in-local-mode?forum=sqlreportingservices * * * * ----------------------------- کار 3 -------------------------------------------------------------- * در کانفیگ این کار را هم طبق پست روبرو انجام دادیم. سرعت به طرز وحشتناکی خوب شد : https://social.msdn.microsoft.com/Forums/en-US/b35bf409-4d73-4506-b13b-2629b1216773/reportviewer-in-net-4-even-possible-legacycasmodelquottruequot-causes-problems?forum=vsreportcontrols * اما محدودیت آن فراوان است * * در بخش system.web : * <trust legacyCasModel="true" level="Full"/> * البته در صورتیکه برنامه شما یک وب سایت نیست از طریق این تنظیم runtime: (طبق لینک روبرو این تگ با NetFx40_LegacySecurityPolicy تفاوتی ندارد : https://blogs.msdn.microsoft.com/shawnfa/2009/06/12/temporarily-re-enabling-cas-policy-during-migration/) * <legacyCasPolicy enabled="true" /> * * در تنظیمات اسمبلی همین اسمبلی باید خط زیر را اضافه کنید : https://stackoverflow.com/a/2504341/790811 * برای همین کار مجبور هستیم کل پروژه را جدا کنیم چراکه برای بخش های دیگر دچار مشکل می کند * [assembly: AllowPartiallyTrustedCallers] * * و در کد دقیقا در همین محل عملیات زیر انجام شد : * var customAssembly = typeof(ReportsLoader).Assembly; * report.AddTrustedCodeModuleInCurrentAppDomain(customAssembly.FullName); * * */ //این کد در صورتی اثر می کند که در کانفیگ برنامه تنظیم گفته شده در توضیحات انجام شده باشد //توجه: اسمبلی را دستی نوشتیم. دقت کنید که اگر از خود اسمبلی می گرفتیم ورژن هم داشت و ما نباید //در این نام آنرا به ورژن وابسته کنیم if (RunInLegacyCasModel) { report.AddTrustedCodeModuleInCurrentAppDomain("Greewf.Reporting, Culture=neutral, PublicKeyToken=ebf2eb006a1f561b"); } else { var assembly = typeof(ReportsLoader).Assembly; report.AddFullTrustModuleInSandboxAppDomain(CreateStrongName(assembly)); } var defaults = report.GetDefaultPageSettings(); var marginTop = settings.TopMargin.HasValue ? (settings.TopMargin * (1 / 2.54)) : defaults.Margins.Top / 100.0; var marginBottom = settings.BottomMargin.HasValue ? (settings.BottomMargin * (1 / 2.54)) : defaults.Margins.Bottom / 100.0; var marginLeft = settings.LeftMargin.HasValue ? (settings.LeftMargin * (1 / 2.54)) : defaults.Margins.Left / 100.0; var marginRight = settings.RightMargin.HasValue ? (settings.RightMargin * (1 / 2.54)) : defaults.Margins.Right / 100.0; settings.EndPage = settings.EndPage ?? settings.StartPage; //The DeviceInfo settings should be changed based on the reportType // http://msdn2.microsoft.com/en-us/library/ms155397.aspx // http://msdn.microsoft.com/en-us/library/hh231593.aspx string deviceInfo = "<DeviceInfo>" + ((settings.DpiX > 0) ? " <DpiX>" + settings.DpiX + "</DpiX>" : "") + ((settings.DpiY > 0) ? " <DpiY>" + settings.DpiY + "</DpiY>" : "") + " <OutputFormat>" + settings.OutputType + "</OutputFormat>" + " <PageWidth>" + (defaults.IsLandscape ? defaults.PaperSize.Height : defaults.PaperSize.Width) / 100.0 + "in</PageWidth>" + " <PageHeight>" + (defaults.IsLandscape ? defaults.PaperSize.Width : defaults.PaperSize.Height) / 100.0 + "in</PageHeight>" + " <MarginTop>" + marginTop + "in</MarginTop>" + " <MarginLeft>" + marginLeft + "in</MarginLeft>" + " <MarginRight>" + marginRight + "in</MarginRight>" + " <MarginBottom>" + marginBottom + "in</MarginBottom>" + " <StartPage>" + (settings.StartPage ?? 0) + "</StartPage>" + " <EndPage>" + (settings.EndPage ?? 0) + "</EndPage>" + " <PageBreaksMode>OnEachPage</PageBreaksMode>" + " <HumanReadablePDF>" + settings.HumanReadablePdf.ToString() + "</HumanReadablePDF>"; if (!settings.EmbedFontsInPdf) { deviceInfo += " <EmbedFonts>None</EmbedFonts>"; } deviceInfo += "</DeviceInfo>"; return(deviceInfo); }
/// <summary> /// Load Report. /// </summary> /// <param name="rptViewer">The instance of Report Viewer Control.</param> /// <param name="reportSource">The instance of RdlcReportModel.</param> public static void LoadReport(this ReportViewer rptViewer, RdlcReportModel reportSource) { RdlcMessageService.Instance.SendMessage("Begin Load Report."); rptViewer.ProcessingMode = ProcessingMode.Local; LocalReport lr = rptViewer.LocalReport; if (null != reportSource && null != reportSource.Definition && null != reportSource.Definition.RdlcInstance && null != reportSource.DataSources) { RdlcMessageService.Instance.SendMessage("Begin Load Report Definition."); // Load Rdlc file lr.LoadReportDefinition(reportSource.Definition.RdlcInstance); RdlcMessageService.Instance.SendMessage("Clear Report Data source."); // Clear all datasource before assign new one. lr.DataSources.Clear(); if (reportSource.DataSources.Count > 0) { // Set all data source. foreach (var dataSource in reportSource.DataSources) { if (null == dataSource.Items) { continue; } RdlcMessageService.Instance .SendMessage("Add New Report Data source - " + dataSource.Name); lr.DataSources.Add(new ReportDataSource( dataSource.Name, dataSource.Items)); } } else { RdlcMessageService.Instance .SendMessage("No New Report Data source."); } if (lr.DataSources.Count > 0 && null != reportSource.Parameters && reportSource.Parameters.Count > 0) { foreach (RdlcReportParameter para in reportSource.Parameters) { if (null == para || string.IsNullOrWhiteSpace(para.Name)) { continue; } try { RdlcMessageService.Instance .SendMessage("Set Report parameter - " + para.Name); lr.SetValue(para.Name, para.Value); } catch (Exception) { } } } else { RdlcMessageService.Instance .SendMessage("No Report parameter assigned."); } if (lr.DataSources.Count > 0) { RdlcMessageService.Instance .SendMessage("Set Report Page setting from Printer page setting."); // Read Setting and set to report viewer ReportPageSettings rdlcPageSettings = lr.GetDefaultPageSettings(); System.Drawing.Printing.PageSettings pageSettings = new System.Drawing.Printing.PageSettings(); pageSettings.PaperSize = rdlcPageSettings.PaperSize; pageSettings.Landscape = rdlcPageSettings.IsLandscape; pageSettings.Margins = rdlcPageSettings.Margins; rptViewer.SetPageSettings(pageSettings); // refresh rptViewer.LocalReport.Refresh(); } else { RdlcMessageService.Instance .SendMessage("No Report data source so cannot set report page setting."); } } rptViewer.RefreshReport(); // Set display mode to print layout. rptViewer.SetDisplayMode(DisplayMode.PrintLayout); if (null != reportSource && null != reportSource.Definition && null != reportSource.Definition.RdlcInstance) { try { reportSource.Definition.Dispose(); } catch { } } }
/// <summary> /// Print Report to specificed printer. /// </summary> /// <param name="rptViewer">The instance of Report Viewer Control.</param> /// <param name="printerName">The target printer name.</param> /// <param name="fromPage">-1 for print all</param> /// <param name="toPage">-1 for print all</param> /// <param name="noOfCopies">The Number of Copies.</param> /// <returns>Returns instance of RdlcPrintResult.</returns> public static RdlcPrintResult PrintTo(this ReportViewer rptViewer, string printerName, int fromPage = -1, int toPage = -1, short noOfCopies = 1) { RdlcPrintResult result = new RdlcPrintResult(); result.Success = false; if (string.IsNullOrWhiteSpace(printerName)) { result.Message = "No printer selected."; RdlcMessageService.Instance.SendMessage(result.Message); return(result); } if (null == rptViewer.LocalReport || null == rptViewer.LocalReport.DataSources || rptViewer.LocalReport.DataSources.Count <= 0) { result.Message = "Report is not loaded or report has no data."; RdlcMessageService.Instance.SendMessage(result.Message); return(result); } LocalReportRenderer prt = null; try { LocalReport lr = rptViewer.LocalReport; ReportPageSettings settings = lr.GetDefaultPageSettings(); if (null == settings) { result.Message = "Cannot get page settings."; RdlcMessageService.Instance.SendMessage(result.Message); return(result); } #region Assign page setting LocalReportPageSettings pageSettings = new LocalReportPageSettings(); if (!settings.IsLandscape) { pageSettings.PageHeight = Convert.ToDouble( (double)settings.PaperSize.Height / (double)100); pageSettings.PageWidth = Convert.ToDouble( (double)settings.PaperSize.Width / (double)100); } else { pageSettings.PageHeight = Convert.ToDouble( (double)settings.PaperSize.Width / (double)100); pageSettings.PageWidth = Convert.ToDouble( (double)settings.PaperSize.Height / (double)100); } pageSettings.MarginLeft = Convert.ToDouble( (double)settings.Margins.Left / (double)100); pageSettings.MarginRight = Convert.ToDouble( (double)settings.Margins.Right / (double)100); pageSettings.MarginTop = Convert.ToDouble( (double)settings.Margins.Top / (double)100); pageSettings.MarginBottom = Convert.ToDouble( (double)settings.Margins.Bottom / (double)100); //pageSettings.MarginLeft = 0; //pageSettings.MarginRight = 0; //pageSettings.MarginTop = 0; //pageSettings.MarginBottom = 0; pageSettings.Landscape = settings.IsLandscape; pageSettings.FromPage = fromPage; pageSettings.ToPage = toPage; #if WYSIWYG // Read Screen Resolution int dx, dy; System.Drawing.Graphics g = rptViewer.CreateGraphics(); try { dx = Convert.ToInt32(g.DpiX); dy = Convert.ToInt32(g.DpiY); } finally { g.Dispose(); } pageSettings.DpiX = dx; pageSettings.DpiY = dy; // Create dialog and re read resolution. System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog(); pd.PrinterSettings.PrinterName = printerName; System.Drawing.Printing.PrinterSettings ps = pd.PrinterSettings; pageSettings.PrintDpiX = ps.DefaultPageSettings.PrinterResolution.X; pageSettings.PrintDpiY = ps.DefaultPageSettings.PrinterResolution.Y; #endif #endregion prt = new LocalReportRenderer(); prt.Print(lr, printerName, pageSettings, noOfCopies); result.Success = true; result.Message = "Print Success."; RdlcMessageService.Instance.SendMessage(result.Message); } catch (Exception ex) { result.Message = ex.ToString(); } finally { if (null != prt) { prt.Dispose(); } prt = null; } return(result); }