iTextCharp c#

时间:2021-06-27 16:12:40
//引用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, )); //表格
//传入列数
//也可传入表示每一列宽度的float[]
var table = new PdfPTable();
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();
}
 
iTextCharp c#