【发布时间】:2020-01-15 08:29:34
【问题描述】:
我只想更改 pdfTable 中字体的大小,以免出现换行符。一个问题是 System.Drawing 和 iTextSharp.Text 中有字体。我错过了 iTextSharp.Text.Font 方法的语法应该是什么样的信息。之后我会对如何将字体应用于整个表格感兴趣。
private void Cmd_Protocoll_Click(object sender, EventArgs e)
{
Document pProtocoll = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10);
PdfWriter.GetInstance(pProtocoll, new FileStream("TestPDF.pdf", FileMode.Create));
pProtocoll.Open();
pProtocoll.SetPageSize(PageSize.A4.Rotate());
pProtocoll.AddTitle("PDF-Erstellung");
string author = Txt_PreName.Text + Txt_LastName.Text;
pProtocoll.AddAuthor(author);
pProtocoll.AddSubject("Was ist das Subject");
PdfPTable pdfPTable = new PdfPTable(7);
pdfPTable.TotalWidth = 750f;
pdfPTable.LockedWidth = true;
float[] widths = new float[] { 3f, 1f, 1f, 5f, 1f, 2f, 1f };
pdfPTable.SetWidths(widths);
PdfPCell cell = new PdfPCell(new Phrase("Prüfprotokol zum Hardwaredatenpunkttest"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfTimes, 6, 2,{ 0, 0, 0 });
try
{
foreach (DataGridViewRow row in Dgv_Data_List.Rows)
{
foreach (DataGridViewCell celle in row.Cells)
{
if (celle.Value.ToString() != null)
{
pdfPTable.AddCell(celle.Value.ToString());
}
else
{
pdfPTable.AddCell(string.Empty);
}
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
pProtocoll.Add(pdfPTable);
pProtocoll.Close();
}
【问题讨论】: