iTextCharp c#

//引用iTextSharp
static void testPdf()
        {
            var document = new Document();
            var writer = PdfWriter.GetInstance(document, new FileStream("./test.pdf",FileMode.Create));
            document.Open();

            //最小元素
            document.Add(new Chunk("Chunk"));

            //段落
            document.Add(new Paragraph("Paragraph"));

            //短语
            document.Add(new Phrase("Phrase"));

            //list
            //是否有编号,是否使用字母进行编号,列表缩进量
            document.Add(new List(true, false, 10));

            //表格
            //传入列数
            //也可传入表示每一列宽度的float[]
            var table = new PdfPTable(3);
            var cell = new PdfPCell(new Phrase("cell"));
            cell.BorderColor=BaseColor.BLUE;
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            table.AddCell(cell);
            document.Add(table);


            var imgUri = new Uri("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_86d58ae1.png");
            var img = Image.GetInstance(imgUri);
            document.Add(img);
            document.Close();
        }

 

posted @ 2019-03-29 18:45  Hey,Coder!  阅读(512)  评论(0编辑  收藏  举报