using iTextSharp.text; using iTextSharp.text.pdf; using System.Text; namespace IStation.DataFile { #pragma warning disable CA1416 // 验证平台兼容性 /// /// /// public class EnginePumpDayReportV1Helper { ///(1单元格内容,2字体,3占位行,4占位列,5行高,6行位置) Document _document; PdfWriter _writer; //BaseFont _baseFont_general = null;//常规字体 BaseFont _baseFont_spec_char;//特殊字符字体 iTextSharp.text.Font _fontSize8; iTextSharp.text.Font _fontSize9_bold; iTextSharp.text.Font _fontSize13_bold; iTextSharp.text.Font _fontSize11; int _currentPage = 0; /// /// 调用打印PDF /// /// /// /// /// public bool Create(string filePath, EnginePumpDayReportParasV1 paras, out string Msg) { if (filePath == "") { Msg = "路径为空"; return false; } if (paras == null) { Msg = "参数为空"; return false; } InitialFont(); //初始化标题中的LOGO图片 InitialTitleLogoImage(); MemoryStream strem = new MemoryStream(); _document = new Document(iTextSharp.text.PageSize.A4); _document.SetMargins(-20, -20, 20,20); _writer = PdfWriter.GetInstance(_document, new FileStream(filePath, FileMode.Create)); _document.Open(); if (this.CreateProductInfoPage(paras)) Msg = "打印成功"; else Msg = "打印失败"; _document.Close(); return true; } //字体 private void InitialFont() { string fileTtc_simsun = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fonts\\msyhl.ttc"); if (!System.IO.File.Exists(fileTtc_simsun)) { if (System.IO.File.Exists(@"C:\Windows\Fonts\msyhl.ttc")) { fileTtc_simsun = @"C:\Windows\Fonts\msyhl.ttc"; } else { if (System.IO.File.Exists(@"C:\Windows\Fonts\msyhl.ttc")) { fileTtc_simsun = @"C:\Windows\Fonts\msyhl.ttc"; } } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); _baseFont_spec_char = BaseFont.CreateFont(fileTtc_simsun + ",1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //读取ttc字体 //BaseFont.CreateFont 的第一个参数,在字体文件后不一定需要跟上“,1”。 //这取决于使用的字体文件是否支持多字体。例如simsun.ttc 包含了“宋体”和“新宋体”两套字体, //那么如果要使用这个字体文件,就必须指明使用哪一套字体,序号从0开始。 //但如果使用的字体文件只有一套字体,则一定不能加“,0”。否则,无论是多加还是少加,都会报错。 //要想知道字体文件是否是多套字体,只需双击打开字体文件,如果有导航的>>和<<按钮,则是有多套字体,否则就不是。 //TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体。 } if (_baseFont_spec_char == null) return; _fontSize8 = new iTextSharp.text.Font(_baseFont_spec_char, 8); _fontSize9_bold = new iTextSharp.text.Font(_baseFont_spec_char, 9, iTextSharp.text.Font.BOLD); _fontSize13_bold = new iTextSharp.text.Font(_baseFont_spec_char, 13, iTextSharp.text.Font.BOLD); _fontSize11 = new iTextSharp.text.Font(_baseFont_spec_char, 11); } #region LOGO图片 System.Drawing.Image _imgTitleCorpLogo = null;//表头的LOGO /// /// LOGO /// public void InitialTitleLogoImage() { //如果Data文件夹下有就优先 string strLogoFullPath = string.Format("{0}\\SelectReportTitleLogo.png", 1); if (strLogoFullPath == null) return; if (System.IO.File.Exists(strLogoFullPath)) { _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath); return; } strLogoFullPath = string.Format("{0}\\CorpLogo.png", 1); if (System.IO.File.Exists(strLogoFullPath)) { _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath); return; } //没有就搜索Infomation文件夹 strLogoFullPath = string.Format("{0}Infomation\\CorpLogo.png", AppDomain.CurrentDomain.BaseDirectory); if (System.IO.File.Exists(strLogoFullPath)) { _imgTitleCorpLogo = System.Drawing.Image.FromFile(strLogoFullPath); } } #endregion /// /// PDF生成 /// public bool CreateProductInfoPage(EnginePumpDayReportParasV1 paras) { if (paras == null) return false; _document.NewPage(); _currentPage++; //var titlePage = "设备健康状态评估日报告";// CreateProductTable(paras); //this.CreateReportNotesTable(titlePage); CreateReportNotesTable(); CreateProductInfoTable(paras.ErangeList); PdfPTable table1 = new PdfPTable(3); float[] widths = { 80, 120, 300 }; table1.SetWidths(widths); PdfPCell cell = new PdfPCell(); cell = this.CreateCell2("设备健康状态评估日报告" + ":", _fontSize8, 1, 1); table1.AddCell(cell); _document.Add(table1); CreatePropTable(); return true; } /// /// /// public void CreatePropTable() { List _allPartPropList = new List(); _allPartPropList.Add(10); PdfPTable table = new PdfPTable(2); float[] widths = { 300, 300 }; table.SetWidths(widths); PdfPCell cell = new PdfPCell(); int endIndex = 0; cell.DisableBorderSide(8); cell.AddElement(this.PropertyTable(38, 0, out endIndex)); table.AddCell(cell); if (endIndex < _allPartPropList.Count && endIndex > -1) { cell = new PdfPCell(); cell.DisableBorderSide(4); cell.AddElement(this.PropertyTable(38, endIndex, out endIndex)); table.AddCell(cell); } _document.Add(table); } /// /// /// /// /// /// /// public PdfPTable PropertyTable(int displayRow, int startIndex, out int endIndex) { PdfPTable table = new PdfPTable(2); float[] widths = { 300, 300 }; table.SetWidths(widths); PdfPCell cell = new PdfPCell(); int row = 0;//记录循环的行数 string groupName = string.Empty; if (row != 0) { cell = CreateCell2("", _fontSize9_bold, 2, 1, 10, 15); table.AddCell(cell); row++; } groupName = "名称"; cell = CreateCell1("名称", _fontSize9_bold, 2, 1, 13, 15); table.AddCell(cell); row++; cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0, iTextSharp.text.Rectangle.ALIGN_LEFT, Element.ALIGN_LEFT, true); cell.PaddingLeft = 8; table.AddCell(cell); cell = CreateCell2("名称", _fontSize8, 1, 1, 13, 0); cell.PaddingLeft = 8; table.AddCell(cell); row++; endIndex = -1; return table; } private PdfPCell AddPicture(System.Drawing.Image image, int colspan, int rowspan, float cellHeight, int BorderWidthLeft = -1, int BorderWidthRight = -1, int BorderWidthTop = -1, int BorderWidthBottom = -1, float fixHeight = -1) { if (image == null) return null; PdfPCell cell = new PdfPCell(); cell.Colspan = colspan; cell.Rowspan = rowspan; cell.MinimumHeight = cellHeight; cell.FixedHeight = cellHeight; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.HorizontalAlignment = Element.ALIGN_CENTER; if (BorderWidthLeft >= 0) cell.BorderWidthLeft = BorderWidthLeft; if (BorderWidthLeft >= 0) cell.BorderWidthRight = BorderWidthRight; if (BorderWidthTop >= 0) cell.BorderWidthTop = BorderWidthTop; if (BorderWidthBottom >= 0) cell.BorderWidthBottom = BorderWidthBottom; if (fixHeight > 0) cell.FixedHeight = fixHeight; while (image.Width > 1800) { image = image.GetThumbnailImage(Convert.ToInt32(image.Width * 0.9), Convert.ToInt32(image.Height * 0.9), () => { return false; }, IntPtr.Zero); } var imgTextSharp = iTextSharp.text.Image.GetInstance(image, BaseColor.White); imgTextSharp.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE; cell.Image = imgTextSharp; return cell; } /// /// 设备信息 /// // public void CreateProductTable(EnginePumpDayReportParasV1 paras) { if (paras == null) return; PdfPTable table = new PdfPTable(4); PdfPCell cell = new PdfPCell(); float[] widths = new float[] { 30, 90, 30, 90 }; cell = this.CreateCell2("设备健康状况日报告", _fontSize13_bold, 4, 1, 40,0 , iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("设备状况", _fontSize13_bold, 4, 1, 30,0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("机泵名称", _fontSize9_bold, 1, 1, 20, 0,iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.EnginePumpName, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("机泵编码", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.EnginePumpNo, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("报告日期", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.ReportDay.ToString(), _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("运行时间", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.RunTime, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("供水量", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.WaterSupply, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("耗电", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.ConsumePower, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("平均效率", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.AverageEfficiency, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("标准煤", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(paras.StandardCoal, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); table.SetWidths(widths); _document.Add(table); } /// /// 详细描述 /// public void CreateReportNotesTable() { PdfPTable table = new PdfPTable(3); PdfPCell cell = new PdfPCell(); float[] widths = new float[] { 40, 40, 240 }; cell = this.CreateCell2("报告注释", _fontSize11, 0, 6, 45, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("优秀", _fontSize11, 1, 1, 45, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Green; table.AddCell(cell); cell = this.CreateCell2("表示设备状态极好,无任何异常迹象,无需任何处理措施;", _fontSize11, 2, 1, 45); table.AddCell(cell); cell = this.CreateCell2("良好", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Cyan; table.AddCell(cell); cell = this.CreateCell2("表示设备状态正常,具有某些早期故障征兆,振动很小但稳定,无需任何处理措施,常规监控即可;", _fontSize11, 2, 1, 60); table.AddCell(cell); cell = this.CreateCell2("观察", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Yellow; table.AddCell(cell); cell = this.CreateCell2("表示设备设备状态基本正常,振动有所增大但仍在允许范围内 某些早期故障征兆有进一步发展,需要加强监控观察运行;", _fontSize11, 2, 1, 45); table.AddCell(cell); cell = this.CreateCell2("警告", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Orange; table.AddCell(cell); cell = this.CreateCell2("表示设备振动或温度测量值偏大,超过了ISO 10816-7和ISO 10816-3的一级阈值,需要在适当的时候对设备进行检查;", _fontSize11, 2, 1, 45); table.AddCell(cell); cell = this.CreateCell2("危险", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Red; table.AddCell(cell); cell = this.CreateCell2("表示设备振动或温度测量值偏大,超过了ISO 10816-7和ISO 10816-3的一级阈值,需要在适当的时候对设备进行检查;", _fontSize11, 2, 1, 45); table.AddCell(cell); cell = this.CreateCell2("离线", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); cell.BackgroundColor = BaseColor.Gray; table.AddCell(cell); cell = this.CreateCell2("表示该测点不在正常测量中,可能的情况包括采集设备故障、设备停机、非ok、已拆除等;", _fontSize11, 2, 1, 45); table.AddCell(cell); table.SetWidths(widths); _document.Add(table); } /// /// /// /// public void CreateProductInfoTable(List> pairs) { if (pairs == null) return; PdfPTable table = new PdfPTable(4); PdfPCell cell = new PdfPCell(); float[] widths = new float[] { 30, 90, 30, 90 }; cell = this.CreateCell2("效率区间", _fontSize13_bold, 4, 1, 30, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); foreach (var pair in pairs) { cell = this.CreateCell2("效率", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(pair.Key, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2("时间", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); cell = this.CreateCell2(pair.Value, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); table.AddCell(cell); table.SetWidths(widths); } _document.Add(table); } ///// ///// ///// ///// //public void CreateProductInfoTable(List> pairs) //{ // if (pairs == null) // return; // PdfPTable table = new PdfPTable(4); // PdfPCell cell = new PdfPCell(); // float[] widths = new float[] { 30, 90, 30, 90 }; // cell = this.CreateCell2("效率区间", _fontSize13_bold, 4, 1, 30, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // foreach (var pair in pairs) // { // cell = this.CreateCell2("效率", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2(pair.Key, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("时间", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2(pair.Value, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // table.SetWidths(widths); // } // _document.Add(table); //} /////// /////// 设备信息 /////// ////// ////public void CreateProductTable(EnginePumpDayReportParasV1 paras) ////{ //// if (paras == null) //// return; //// PdfPTable table = new PdfPTable(2); //// PdfPCell cell = new PdfPCell(); //// float[] widths = new float[] { 37, 260 }; //// cell = this.CreateCell2("设备健康状况日报告", _fontSize13_bold, 2, 1, 40, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2("机泵名称", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2(paras.EnginePumpName, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2("机泵编码", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2(paras.EnginePumpNo, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2("报告日期", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2(paras.ReportDay.ToString(), _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2("运行时间", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// cell = this.CreateCell2(paras.RunTime, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// table.AddCell(cell); //// //cell = this.CreateCell2("供水量", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2(paras.WaterSupply, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2("耗电", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2(paras.ConsumePower, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2("平均效率", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2(paras.AverageEfficiency, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2("标准煤", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// //cell = this.CreateCell2(paras.StandardCoal, _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); //// //table.AddCell(cell); //// table.SetWidths(widths); //// _document.Add(table); ////} ///// ///// 报告信息 ///// ///// //public void CreateReportNotesTable(string name) //{ // PdfPTable table = new PdfPTable(3); // PdfPCell cell = new PdfPCell(); // float[] widths = new float[] { 40, 40,240 }; // cell = this.CreateCell2("报告注释", _fontSize11, 0, 6, 45, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("优秀", _fontSize11, 1, 1, 45, 0,iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Green; // table.AddCell(cell); // cell = this.CreateCell2("表示设备状态极好,无任何异常迹象,无需任何处理措施;", _fontSize11, 2, 1, 45, 2); // table.AddCell(cell); // cell = this.CreateCell2("良好", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Cyan; // table.AddCell(cell); // cell = this.CreateCell2("表示设备状态正常,具有某些早期故障征兆,振动很小但稳定,无需任何处理措施,常规监控即可;", _fontSize11, 2, 1, 45, 2); // table.AddCell(cell); // cell = this.CreateCell2("观察", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Yellow; // table.AddCell(cell); // cell = this.CreateCell2("表示设备设备状态基本正常,振动有所增大但仍在允许范围内 某些早期故障征兆有进一步发展,需要加强监控观察运行;", _fontSize11, 2, 1, 45, 2); // table.AddCell(cell); // cell = this.CreateCell2("警告", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Orange; // table.AddCell(cell); // cell = this.CreateCell2("表示设备振动或温度测量值偏大,超过了ISO 10816-7和ISO 10816-3的一级阈值,需要在适当的时候对设备进行检查;", _fontSize11, 2, 1, 45, 2); // table.AddCell(cell); // cell = this.CreateCell2("危险", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Red; // table.AddCell(cell); // cell = this.CreateCell2("表示设备振动或温度测量值偏大,超过了ISO 10816-7和ISO 10816-3的一级阈值,需要在适当的时候对设备进行检查;", _fontSize11, 2, 1, 45, 0); // table.AddCell(cell); // cell = this.CreateCell2("离线", _fontSize11, 1, 1, 45, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.LightGray; // table.AddCell(cell); // cell = this.CreateCell2("表示该测点不在正常测量中,可能的情况包括采集设备故障、设备停机、非ok、已拆除等;", _fontSize11, 2, 1, 45, 0); // table.AddCell(cell); // cell.Rowspan = 4; // table.SetWidths(widths); // _document.Add(table); //} ///// ///// 设备详情 ///// ///// //public void CreateProductInfoTable() //{ // PdfPTable table = new PdfPTable(3); // PdfPCell cell = new PdfPCell(); // float[] widths = new float[] { 40, 40, 240 }; // ///(1单元格内容,2字体,3占位行,4占位列,5行高,6行位置) // cell = this.CreateCell2("设备信息", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("机组名称", _fontSize9_bold, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("设备编号", _fontSize9_bold, 1, 1, 20, 2, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("※※※※※※※※※※※※※※※※分割线※※※※※※※※※※※※※※※※※※", _fontSize11, 3, 1, 25, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("设备名称", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("21" + "日状态", _fontSize11, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("设备历史信息", _fontSize9_bold, 1, 1, 20, 2, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("启动次数", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("1", _fontSize11, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("停机次数", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("设备部位详细历史状态", _fontSize9_bold, 3, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("位置", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("状态", _fontSize9_bold, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("位置", _fontSize9_bold, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("德克萨斯", _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("OK", _fontSize11, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Cyan; // table.AddCell(cell); // cell = this.CreateCell2("德克萨斯", _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("德克萨斯", _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell = this.CreateCell2("OK", _fontSize11, 1, 1, 20, 1, iTextSharp.text.Rectangle.ALIGN_CENTER); // cell.BackgroundColor = BaseColor.Cyan; // table.AddCell(cell); // cell = this.CreateCell2("德克萨斯", _fontSize11, 1, 1, 20, 0, iTextSharp.text.Rectangle.ALIGN_CENTER); // table.AddCell(cell); // cell.Rowspan = 4; // table.SetWidths(widths); // _document.Add(table); //} ////添加水印 //public void AddWatermark() //{ // if (_isPrintCorpWaterMark) // { // var waterMarkLogoFile = System.IO.Path.Combine(SPump.GlobeParas.DataFolder, "SelectReportWaterMark.png"); // if (System.IO.File.Exists(waterMarkLogoFile)) // { // PdfContentByte cb = _writer.DirectContent; // iTextSharp.text.Rectangle psize = _document.PageSize; // float width = psize.Width; // float height = psize.Height; // iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(waterMarkLogoFile); // image.ScalePercent(50); // //水印的位置 // //var i = image.Width; // image.SetAbsolutePosition(width / 2 - image.Width / 4, height / 2 - image.Height / 4); // cb.AddImage(image); // } // } // if (!string.IsNullOrEmpty(RefWaterMarkText)) // { // Font font = new Font(Font.FontFamily.UNDEFINED, 30, Font.BOLD, new iTextSharp.text.BaseColor(100, 200, 200, 50)); // Phrase p = new Phrase(RefWaterMarkText, font); // ColumnText.ShowTextAligned(_writer.DirectContent, Element.ALIGN_CENTER, p, _document.PageSize.Width - 100, _document.PageSize.Height - 100, 0); // } //} //为英文时首字母大写 private PdfPCell CreateCell1(string name, iTextSharp.text.Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = iTextSharp.text.Rectangle.ALIGN_LEFT) { Paragraph table_t = null; PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); if (font == null) font = _fontSize8; if (name == null) { name = ""; } table_t = new Paragraph(name, font); table_t.Leading = 9; cell.Colspan = col; cell.Rowspan = row; cell.MinimumHeight = rowHeight; cell.FixedHeight = rowHeight; cell.DisableBorderSide(disableNum); cell.Padding = 0; cell.PaddingLeft = 3; cell.UseAscender = true; cell.UseDescender = true; cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中 cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中 table_t.Alignment = r; cell.AddElement(table_t); return cell; } //绘制文本(可能有特殊字符) private PdfPCell CreateCell2(string name, iTextSharp.text.Font font = null, int col = 1, int row = 1, float rowHeight = 30, int disableNum = 0, int r = iTextSharp.text.Rectangle.ALIGN_LEFT, int Paragraph = Element.ALIGN_LEFT, bool b = false, int strLength = 26) { Paragraph table_t = null; PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); if (font == null) font = _fontSize8; if (name == null) { name = ""; } if (name.Length > 27 && b && name.Length > strLength) { name = name.Substring(0, strLength); } table_t = new Paragraph(name, font); table_t.Alignment = Element.ALIGN_LEFT; cell.Colspan = col; cell.Rowspan = row; cell.MinimumHeight = rowHeight; cell.FixedHeight = rowHeight; cell.DisableBorderSide(disableNum); cell.Padding = 0; cell.PaddingLeft = 3; cell.UseAscender = true; cell.UseDescender = true; cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中 cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中 table_t.Alignment = r; cell.AddElement(table_t); return cell; } private PdfPCell CreateCell(double value, iTextSharp.text.Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = iTextSharp.text.Rectangle.ALIGN_LEFT) { string value_v = string.Empty; Paragraph table_t = null; PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); if (font == null) font = _fontSize8; if (value >= 0) { value_v = Math.Round(value, 4).ToString(); } table_t = new Paragraph(value_v, font); table_t.Leading = 9; cell.Colspan = col; cell.Rowspan = row; cell.MinimumHeight = rowHeight; cell.FixedHeight = rowHeight; cell.DisableBorderSide(disableNum); cell.Padding = 0; cell.PaddingLeft = 3; cell.UseAscender = true; cell.UseDescender = true; cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中 cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中 table_t.Alignment = r; cell.AddElement(table_t); return cell; } //约分 private PdfPCell CreateCellReduce(double value, iTextSharp.text.Font font = null, int col = 1, int row = 1, float rowHeight = 15, int disableNum = 0, int r = iTextSharp.text.Rectangle.ALIGN_LEFT) { string value_v = string.Empty; Paragraph table_t = null; PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(); if (font == null) font = _fontSize8; if (value >= 0) { value_v = Math.Round(value, 2).ToString(); } table_t = new Paragraph(value_v, font); table_t.Leading = 9; cell.Colspan = col; cell.Rowspan = row; cell.MinimumHeight = rowHeight; cell.FixedHeight = rowHeight; cell.DisableBorderSide(disableNum); cell.Padding = 0; cell.PaddingLeft = 3; cell.UseAscender = true; cell.UseDescender = true; cell.HorizontalAlignment = Element.ALIGN_CENTER;//水平居中 cell.VerticalAlignment = Element.ALIGN_MIDDLE;//垂直居中 table_t.Alignment = r; cell.AddElement(table_t); return cell; } //画单元格方法 private PdfPTable CreateTable(int spanNum, float percentage = 100)//建立表格 { PdfPTable table1 = new PdfPTable(spanNum);//将表格分为10列 table1.WidthPercentage = percentage;//表格所占界面的百分比 return table1; } } #pragma warning restore CA1416 // 验证平台兼容性 }