using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace testPdf
{
class Program
{
static void Main(string[] args)
{
BaseFont BF_Light = BaseFont.CreateFont(@"C:\Windows\Fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(string.Format("Demo.pdf"),FileMode.Create));
doc.Open();
Paragraph p = new Paragraph("标题\n\n",new Font(BF_Light,18));
p.Alignment = 1;//居中
doc.Add(p);
p = new Paragraph("第一个单元格", new Font(BF_Light,12));//测试再次调用P
PdfPCell cell = new PdfPCell(p);
cell.HorizontalAlignment = 1;//设置单元格内居中
//cell.VerticalAlignment = 1;
int[] widths = { 5, 10 };
PdfPTable dt1 = new PdfPTable(2);
dt1.SetWidths(widths);//设置每列的宽度(求和百分比5,10=1,2)
cell.Rowspan = 2;//设置跨度行数(Colspan设置跨度列数)
dt1.AddCell(cell);
dt1.AddCell(new PdfPCell(new Paragraph("第二个单元格", new Font(BF_Light, 12))));
dt1.AddCell(new PdfPCell(new Paragraph("第三个单元格", new Font(BF_Light, 12))));
doc.Add(dt1);
PdfPCell cell3 = new PdfPCell(new Paragraph("最后一个", new Font(BF_Light)));
PdfPTable dt3 = new PdfPTable(2);
dt3.AddCell(cell3);
dt3.WidthPercentage = 85;
PdfPCell cell4 = new PdfPCell(new Paragraph("再加一个", new Font(BF_Light)));
dt3.AddCell(cell4);
doc.Add(dt3);
doc.Close();
}
}
}