在itextsharp上字体大小很大,边缘不会改变 [英] font size is to big on itextsharp and side margin wont change
问题描述
请修改我的代码。
我一直在为左右两边的字体和边距工作大约一个小时..
完美无缺。但左右边距似乎没有变化和字体一样。
这是按钮导出pdf的部分。
PdfPTable pdftable = new PdfPTable(GridView1.HeaderRow.Cells.Count);
foreach (TableCell headerCell in GridView1.HeaderRow.Cells)
{
Font font = new 字体();
font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell( new 短语(headerCell.Text,font ));
pdfcell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor);
pdftable.AddCell(pdfcell);
}
foreach (GridViewRow gridViewRow GridView1.Rows)
{
foreach (TableCell tableCell in gridViewRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(GridView1.RowStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell( new Phrase(tableCell.Text)) ;
pdfcell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor);
pdftable.AddCell(pdfcell);
}
}
文件pdfDocument = 新文件(PageSize.LETTER,10f,10f,10f,10f) ;
pdfDocument.SetPageSize(PageSize.LETTER.Rotate());
PdfWriter.GetInstance(pdfDocument,Response.OutputStream);
pdfDocument.Open();
float [] widths = new float [] {1f,2f,3f,10f,6f,4f}; // 每列大小
pdftable.SetWidths(widths);
pdfDocument.Add(pdftable);
pdfDocument.Close();
Response.ContentType = application / pdf;
Response.AppendHeader( Content-disposition, attachment; filename = jalisto.pdf);
Response.Write(pdfDocument);
Response.Flush();
Response.End();
对于字体,您可以使用字体工厂,例如
Font font = FontFactory.GetFont( Arial,10f,Font .NORMAL,iTextSharp.text.BaseColor.BLACK);
或实例化新的font()对象如:
BaseFont basefont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252, false );
Font font = new 字体(basefont, 12 ,Font.ITALIC,Color.RED) ;
如需更多说明,请点击以下链接:
< a href =http://www.mikesdotnetting.com/Article/81/itextsharp-working-with-fonts> http://www.mikesdotnetting.com/Article/81/itextsharp-working-with-fonts [ ^ ]
please modify my code.
ive been working for the font and the margin from left and right for about an hours..
this works perfectly.but margin from left and right seems not changing as well as font.
this is the part where the button export pdf.
PdfPTable pdftable = new PdfPTable(GridView1.HeaderRow.Cells.Count);
foreach (TableCell headerCell in GridView1.HeaderRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell(new Phrase(headerCell.Text, font));
pdfcell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor);
pdftable.AddCell(pdfcell);
}
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
foreach (TableCell tableCell in gridViewRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(GridView1.RowStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell(new Phrase(tableCell.Text));
pdfcell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor);
pdftable.AddCell(pdfcell);
}
}
Document pdfDocument = new Document(PageSize.LETTER, 10f, 10f, 10f, 10f);
pdfDocument.SetPageSize(PageSize.LETTER.Rotate());
PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
pdfDocument.Open();
float[] widths = new float[] { 1f, 2f,3f,10f,6f,4f}; // size per column
pdftable.SetWidths(widths);
pdfDocument.Add(pdftable);
pdfDocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-disposition", "attachment;filename=jalisto.pdf");
Response.Write(pdfDocument);
Response.Flush();
Response.End();
For font you can use font factory like
Font font = FontFactory.GetFont("Arial", 10f, Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
or instantiate new font() object like:
BaseFont basefont= BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); Font font= new Font(basefont, 12, Font.ITALIC, Color.RED);
For more clarification you can follow this link :
http://www.mikesdotnetting.com/Article/81/itextsharp-working-with-fonts[^]
这篇关于在itextsharp上字体大小很大,边缘不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!