原由于系统报表工具使用的RDLC,本地测试一直使用的纵向打印,未测试过横向打印😭。前端
甲方提供的打印机为HP1106,支持纵向打印,但!领导要求必须横向打印😇,所以还拖延了实施进度😳。后端
先总结一下遇到的问题ide
微软官方RDLC报表工具使用起来不太方便,也因单据复杂度而异。工具
在遇到这个问题时上网搜索发现,一致认为此问题为BUG,在CS端能够解决,可是BS端未提供解决方案。测试
可是搜索时大部分文章标题为”RDLC宽大于高 横向打印失效“或反之。spa
因而将计就计,个人报表为A5横向,改成A4纵向,这样打印时可打印A5横向。设计
此行为纯属偷懒行为,若以为不可用,可将解决方案分享或换一个报表工具。 3d
个人代码以下code
/// <summary> /// RDLC报表帮助类 /// </summary> public static class RDLCHelper { /// <summary> /// 下载打印文件 /// </summary> /// <param name="option">报表设置项</param> /// <param name="str_dataSource">报表数据集名称</param> /// <param name="data">数据源</param> /// <param name="renderedBytes">报表二进制流</param> /// <param name="mimeType">报表mimeType</param> public static void DownloadFile<T>(ReportOption option, string str_dataSource, List<T> data, out byte[] renderedBytes, out string mimeType) { LocalReport localReport = new LocalReport(); localReport.EnableExternalImages = true; localReport.ReportPath = HttpContext.Current.Server.MapPath(option.ReportServerUrl); ReportDataSource reportDataSource = new ReportDataSource(str_dataSource, data); localReport.DataSources.Add(reportDataSource); string encoding; string fileNameExtension; string deviceInfo = "<DeviceInfo>" + "<OutPutFormat>" + option.OutPutFormat + "</OutPutFormat>" + "<PageWidth>" + option.PageWidth + "</PageWidth>" + "<PageHeight>" + option.PageHeight + "</PageHeight>" + "<MarginTop>" + option.MarginTop + "</MarginTop>" + "<MarginLeft>" + option.MarginLeft + "</MarginLeft>" + "<MarginRight>" + option.MarginRight + "</MarginRight>" + "<MarginBottom>" + option.MarginBottom + "</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; renderedBytes = localReport.Render( option.OutPutFormat, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings ); } /// <summary> /// 报表设置项 /// </summary> public class ReportOption { /// <summary> /// 报表文件路径 /// </summary> public string ReportServerUrl { get; set; } /// <summary> /// 文件类型 /// </summary> public string OutPutFormat { get; set; } /// <summary> /// 页宽,不包含单位(cm厘米,in英寸) /// </summary> public string PageWidth { get; set; } /// <summary> /// 页高,不包含单位(cm厘米,in英寸) /// </summary> public string PageHeight { get; set; } /// <summary> /// 外边距顶部值,设计页面外部累加值,不包含单位(cm厘米,in英寸) /// </summary> public string MarginTop { get; set; } /// <summary> /// 外边距底部值,设计页面外部累加值,不包含单位(cm厘米,in英寸) /// </summary> public string MarginBottom { get; set; } /// <summary> /// 外边距左部值,设计页面外部累加值,不包含单位(cm厘米,in英寸) /// </summary> public string MarginLeft { get; set; } /// <summary> /// 外边距右部值,设计页面外部累加值,不包含单位(cm厘米,in英寸) /// </summary> public string MarginRight { get; set; } } }
public ActionResult Print(string DEVICE_ID, string type) { List<bill> bill = new List<bill>(); RDLCHelper.ReportOption option = new RDLCHelper.ReportOption { ReportServerUrl = "~/Template/bill.rdlc", OutPutFormat = type, PageWidth = "21cm",//注意此处设置的A4纵向格式 PageHeight = "29.7cm",//但实际报表为A5横向 MarginTop = "0cm", MarginBottom = "0cm", MarginLeft = "0cm", MarginRight = "0cm" }; byte[] renderedBytes; string mimeType; RDLCHelper.DownloadFile(option, "billData", bill, out renderedBytes, out mimeType); return File(renderedBytes, mimeType); }
function Print() { window.open("/bbbb/billm/bill?type=pdf&DEVICE_ID=" + DeviceId , 'newwindow', 'height=800, width=1200, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); }