如何在C#中使用iTextSharp将数据表导出为PDF?
public void ExportToPdf(DataTable dt)
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("c://sample.pdf", FileMode.Create));
document.Open();
PdfPTable table = new PdfPTable(dt.Columns.Count);
PdfPRow row = null;
float[] widths = new float[] { 2f, 2f, 2f, 2f };
table.SetWidths(widths);
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell(new Phrase("Products"));
cell.Colspan = dt.Columns.Count;
}
Run Code Online (Sandbox Code Playgroud)