zoukankan      html  css  js  c++  java
  • iTextSharp 使用笔记

    用于导出PDF

                iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(1000, 500);
                iTextSharp.text.Document document = new iTextSharp.text.Document(pageSize, 10, 10, 20, 20);
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fName, FileMode.Create));
                document.Open();
                BaseFont baseFont = BaseFont.CreateFont(@"C:WindowsFontsmsyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    
                iTextSharp.text.Font fontb = new iTextSharp.text.Font(baseFont);
                 // 没起作用 ,可以用无边框单元格实现标题
                document.AddTitle(" 标题 ");
    
                PdfPTable pdfTable = new PdfPTable(new float[] { 50, 80, 80, 50, 100, 100, 70, 50, 95, 95 });
                pdfTable.TotalWidth = 900; //表格宽度
                pdfTable.LockedWidth = true;
    
                //将单元格添加到表格中
                AddPdfCell(pdfTable, fontb, "表头1");
                AddPdfCell(pdfTable, fontb, "表头2");
                AddPdfCell(pdfTable, fontb, "表头3");
                AddPdfCell(pdfTable, fontb, "表头4");
                AddPdfCell(pdfTable, fontb, "表头5");
                for (int i = 0; i < dgvUserList.Rows.Count; i++)
                {
                    AddPdfCell(pdfTable, fontb, "内容1");
                    AddPdfCell(pdfTable, fontb, "内容2");
                    AddPdfCell(pdfTable, fontb, "内容3");
                    AddPdfCell(pdfTable, fontb, "内容4");
                    AddPdfCell(pdfTable, fontb, "内容5");
                  
                }
    
                document.Add(pdfTable);//将表格添加到pdf文档中
                document.Close();
                writer.Close();            

    用到的AddPdfCell

    private static void AddPdfCell(PdfPTable pdfTable, iTextSharp.text.Font fontb, string text)
            {
                PdfPCell pdfCell = new PdfPCell(new Paragraph(text, fontb));
                pdfCell.HorizontalAlignment = 1;
                pdfCell.PaddingBottom = 10;
                pdfCell.PaddingTop = 10;
                pdfCell.BorderColor = BaseColor.BLACK;
                pdfCell.SetLeading(1.2f, 1.2f);
                pdfTable.AddCell(pdfCell);
            }

    后期总结的一个 AddPdfCell

    private static void AddPdfCell(PdfPTable pdfTable, 
                iTextSharp.text.Font fontb, string text,int rowspan,int colspan,BaseColor color)
            {
                PdfPCell pdfCell = new PdfPCell(new Paragraph(text, fontb));
                pdfCell.HorizontalAlignment = 1;
                pdfCell.PaddingBottom = 10;
                pdfCell.PaddingTop = 10;
                pdfCell.Rowspan = rowspan;
                pdfCell.Colspan = colspan;
                pdfCell.BorderColor = color;  
                pdfCell.SetLeading(1.2f, 1.2f);
                pdfTable.AddCell(pdfCell);
            }

    导出图片

    private void BeforeChartImg(List<string> chartData)
            {
                if (chartData == null) return;
                foreach (var strChar in chartData)
                {
                    string[] arr = strChar.Split(new string[] { "base64," }, StringSplitOptions.RemoveEmptyEntries);
                    byte[] byteArray = null;
    
                    if (arr.Length > 1)
                    {
                        byteArray = Convert.FromBase64String(arr[1]);
                    }
                    else
                    {
                        MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(strChar));
                        MemoryStream tStream = new MemoryStream();
                        Svg.SvgDocument tSvgObj = SvgDocument.Open(tData);
                        tSvgObj.Draw().Save(tStream, ImageFormat.Png);
                        byteArray = tStream.ToArray();
                    }
                    Image png = Image.GetInstance(byteArray);
                    //图片居中显示
                    png.Alignment = 1;
                    //缩放图片
                    ZoomPicture(png, document.PageSize);
                    document.Add(png);
                }
            }
  • 相关阅读:
    php的form中元素name属性相同时的取值问题
    从FCN到DeepLab
    论文学习:Fully Convolutional Networks for Semantic Segmentation
    笔记:基于DCNN的图像语义分割综述
    论文笔记(3):STC: A Simple to Complex Framework for Weakly-supervised Semantic Segmentation
    概念:弱监督学习
    FCN小小实战
    (2)Deep Learning之线性单元和梯度下降
    (1)Deep Learning之感知器
    深度学习实验系列(1)
  • 原文地址:https://www.cnblogs.com/wu-xin/p/13299419.html
Copyright © 2011-2022 走看看